Set sysdate as List parameter in oracle reports - oraclereports

I am trying to set SYSDATE-1 in list parameter in oracle report. Input mask is mm/dd/yyyy HH24:MI:SS
now how can I set in the list parameter as SYSDATE-1 00:00:00. When I try to set it is throwing as error.
value does not match with the input mask please suggest how can I do this.

Let pretend that sysdate is 2014.12.19 18:26:58:
TO_CHAR(SYSDATE, 'mm/dd/yyyy HH24:MI:SS') --12/19/2014 18:26:58
TO_CHAR(SYSDATE - 1, 'mm/dd/yyyy HH24:MI:SS') --12/18/2014 18:26:58
TO_CHAR(SYSDATE - 1, 'mm/dd/yyyy') --12/18/2014
TO_CHAR(TRUNC(SYSDATE) - 1, 'mm/dd/yyyy HH24:MI:SS') --12/18/2014 00:00:00
TO_CHAR(TRUNC(SYSDATE - 1), 'mm/dd/yyyy HH24:MI:SS') --12/18/2014 00:00:00
TO_CHAR(SYSDATE - 1, 'mm/dd/yyyy')||' 00:00:00' --12/18/2014 00:00:00
TO_CHAR(SYSDATE - 1)||' 00:00:00' --2014.12.18 00:00:00
Not sure for this one
TO_CHAR(ROUND(SYSDATE) - 1, 'mm/dd/yyyy HH24:MI:SS'') --12/18/2014 00:00:00

Related

SSRS tweak to time expression

I am currently using this expression to show the previous working day in an SSRS report:
=DateAdd("d"
, Switch(DatePart("w", Today) = 2, -3
,DatePart("w", Today) = 1, -2
,True, -1)
, Today)
which works fine.
However I would like the output to be,if I ran the query today for example,:
24/04/2020 23:59:59
Instead of the current 24/04/2020
Please can you advise on how I could add hours, minutes and seconds- 23:59:59 - to the above expression?
Thank you
There may be a more elegant way of doing this but I based this on you current expression. I've text it and it seems to work OK.
=DateAdd("s"
, Switch(
DatePart("w", Today) = 2, (-3 * 86400) -1,
DatePart("w", Today) = 1, (-2 * 86400) -1,
True, -85401
)
, Today)
This simply does a datediff in seconds rather than days and then adjusts the amount of seconds to remove by 1

Is there a way to write and DateAdd and DatePart SSIS Expression to always generate ThisWeekMonday's date using Getdate()?

I have a package that needs to be run every Monday, because the file dates all have Monday's dates for each week that it is sent. If the package fails for some reason, I want to I to write it in such a way that anybody else can rerun it on any other day of the week. Regardless of which day it is run, it must generate Monday's date of each week to pick up the correct file.
I tried using the following expression, but it generated last week's Monday's date when it is run on a Monday:
DATEADD( "dd", -1 - (DATEPART("dw", GETDATE()) + 4) % 7, GETDATE() ).
I altered the parameters several times, but still couldn't get it to work.
Someone gave me this expression, but it didn't work at all for Monday even after changing the parameters:
DATEADD( "dd", (DATEPART( "dw", GETDATE() ) -3), GETDATE() )
Finally, I tried using the following statement which is equivalent to a Case statement in SQL, but it gave me an error in the first part of each line shown below (NOTE: square brackets were not included.)
[ DATEPART( "dw", GETDATE()) ]
See my complete expression below:
DATEPART( "dw", GETDATE()) == 1 ? DATEADD( "dd", 1, GETDATE()) : (
DATEPART( "dw", GETDATE()) == 2 ? DATEADD( "dd", 0, GETDATE()) : (
DATEPART( "dw", GETDATE()) == 3 ? DATEADD( "dd", -1, GETDATE()) : (
DATEPART( "dw", GETDATE()) == 4 ? DATEADD( "dd", -2, GETDATE()) : (
DATEPART( "dw", GETDATE()) == 5 ? DATEADD( "dd", -3, GETDATE()) : (
DATEPART( "dw", GETDATE()) == 6 ? DATEADD( "dd", -4, GETDATE()) : (
DATEPART( "dw", GETDATE()) == 7 ? DATEADD( "dd", -5, GETDATE()) ))))))
Can anyone help me to resolve this?
Thanks in advance.
Use the following expression:
DateAdd("dd", 2 - DatePart("dw", GetDate()) , GetDate())
To explain, 2 (which is Monday) - any other day of the week gives you the day offset which can be added to the current day.
e.g. 2 (Monday) - 6 (Friday) = -4 so adding -4 days to Friday gives you Monday.
Hope this helps.

Date Time Format in SQL Server

Can any one guide me to get below date Format?
18th Mar 2014
I do see other date formats are supported. But nd, th after date is needed for me.
Maybe not the simplest way, but this should do it;
SELECT CAST(DATEPART(d, dt) AS NVARCHAR(2)) +
CASE DATEPART(d, dt) WHEN 1 THEN 'st' WHEN 2 THEN 'nd'
WHEN 3 THEN 'rd' WHEN 21 THEN 'st'
WHEN 22 THEN 'nd' WHEN 23 THEN 'rd'
WHEN 31 THEN 'st' ELSE 'th' END +
CAST(SUBSTRING(CONVERT(NVARCHAR(256), dt, 106), 3, 256) AS NVARCHAR(256))
AS [myDate]
FROM test;
An SQLfiddle to test with.
Try this
SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), Left(CONVERT(VARCHAR(11), GETDATE(), 106),2), Left(CONVERT(VARCHAR(11), GETDATE(), 106),2) + 'th') AS [DD Mon YYYY]
Fiddle Demo

How do I get a breakdown by the hour using a single query in MySql?

Let's say my table looks like this:
Sessions
start_dts (datetime)
end_dts (datetime)
and the data looks like this:
start_dts end_dts
12/25/2011 01:55:00 12/25/2011 03:30:00
I need the query results to look like this:
Date Hour MinutesOnline
12/25/2011 0 0
12/25/2011 1 5
12/25/2011 2 60
12/25/2011 3 30
... (every hour of the date range being queried)
Is this even possible with a single query?
Here is a pretty good start. This will work for any date/time range. However, it has one main prerequisite: You need to create an intervals table with a dt_hr datetime field which contains all the intervals you are scanning over.
Ex: '2011-12-25 00:00:00',
'2011-12-25 01:00:00',
'2011-12-25 02:00:00',
'2011-12-25 03:00:00',
. . .
'2011-12-25 23:00:00'
-
SELECT DATE_FORMAT(intervals.dt_hr,'%m/%d/%Y') AS Date,
EXTRACT(HOUR FROM intervals.dt_hr) AS Hour,
CASE
WHEN intervals.dt_hr > TIMESTAMPADD(HOUR,HOUR(s2.start_dts), DATE(s2.start_dts))
AND intervals.dt_hr < TIMESTAMPADD(HOUR,HOUR(s2.end_dts), DATE(s2.end_dts))
THEN 60
WHEN intervals.dt_hr = TIMESTAMPADD(HOUR,HOUR(s2.start_dts), DATE(s2.start_dts))
AND intervals.dt_hr < TIMESTAMPADD(HOUR,HOUR(s2.end_dts), DATE(s2.end_dts))
THEN 60 - EXTRACT(MINUTE FROM s2.start_dts)
WHEN intervals.dt_hr = TIMESTAMPADD(HOUR,HOUR(s2.end_dts), DATE(s2.end_dts))
AND intervals.dt_hr > TIMESTAMPADD(HOUR,HOUR(s2.start_dts), DATE(s2.start_dts))
THEN EXTRACT(MINUTE FROM s2.end_dts)
WHEN intervals.dt_hr = TIMESTAMPADD(HOUR,HOUR(s2.start_dts), DATE(s2.start_dts))
AND intervals.dt_hr = TIMESTAMPADD(HOUR,HOUR(s2.end_dts), DATE(s2.end_dts))
THEN EXTRACT(MINUTE FROM s2.end_dts) - EXTRACT(MINUTE FROM s2.start_dts)
ELSE 0
END AS MinutesOnLine
FROM intervals
LEFT JOIN sessions s2
ON intervals.dt_hr >= TIMESTAMPADD(HOUR,HOUR(s2.start_dts), DATE(s2.start_dts))
AND intervals.dt_hr <= TIMESTAMPADD(HOUR,HOUR(s2.end_dts), DATE(s2.end_dts))
To generate the intervals table, you could create a stored procedure which creates a temporary table with a date_hour sequence. See Get a list of dates between two dates for a way to do this.
More of a big comment than answer.
Not good enough with MySQL to do it but
a CTE to come up with a set of datetimes between start_dts and end_dts
so you get
startTime endTime
12/25/2011 01:00:00 12/25/2011 02:00:00
12/25/2011 02:00:00 12/25/2011 03:00:00
12/25/2011 03:00:00 12/25/2011 04:00:00
joined back to session On CT.EndTime < DateAdd(sessions.end_dts, INTERVAL 1 HOUR)
and then Hour(CTS.StartTime) - Hour(sessions.start_dts)
and modulus of the time difference in minutes beteen cte.endtime and start_dts
maybe...

what is the problem of this mysql query?

SELECT
*
FROM
table_temp
WHERE
install_date < NOW()
AND install_date > DATE_FORMAT(2011 - 06 - 16, "%Y-%m-%d")
The problem resides on theis line:
install_date > DATE_FORMAT(2011 - 06 - 16, "%Y-%m-%d")
The 1st variable should be a string of a date
For example:
SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
Or in your case:
install_date > DATE_FORMAT('2011 - 06 - 16', "%Y-%m-%d")
See MySQL DOC
The value 2011 - 06 - 16 needs to be wrapped up in quotes