SSRS Specify exact date as Default Date Parameter [duplicate] - ssrs-2012

on SSRS report I need to show todays date and current time
i tried this =FormatDateTime(Now,"MM/dd/yyyy hh:mm tt") but this is not working for me giving an error.
Anyone please help me for expression ?
I want output display like 4/12/2013 12:05 PM

=Format(Now(), "MM/dd/yyyy hh:mm tt")
Output:
04/12/2013 05:09 PM
Full list of format options might be found here. Kudos to #MattGibson.

If the date and time is in its own cell (aka textbox), then you should look at applying the format to the entire textbox. This will create cleaner exports to other formats; in particular, the value will export as a datetime value to Excel instead of a string.
Use the properties pane or dialog to set the format for the textbox to "MM/dd/yyyy hh:mm tt"
I would only use Ian's answer if the datetime is being concatenated with another string.

Hope this helps:
SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM
SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy – 10/02/2008
SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd – 2008.10.02
SELECT convert(varchar, getdate(), 103) -- dd/mm/yyyy
SELECT convert(varchar, getdate(), 104) -- dd.mm.yyyy
SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy
SELECT convert(varchar, getdate(), 106) -- dd mon yyyy
SELECT convert(varchar, getdate(), 107) -- mon dd, yyyy
SELECT convert(varchar, getdate(), 108) -- hh:mm:ss
SELECT convert(varchar, getdate(), 109) -- mon dd yyyy hh:mm:ss:mmmAM (or PM)
SELECT convert(varchar, getdate(), 110) -- mm-dd-yyyy
SELECT convert(varchar, getdate(), 111) -- yyyy/mm/dd
SELECT convert(varchar, getdate(), 112) -- yyyymmdd
SELECT convert(varchar, getdate(), 113) -- dd mon yyyy hh:mm:ss:mmm
SELECT convert(varchar, getdate(), 114) -- hh:mm:ss:mmm(24h)
SELECT convert(varchar, getdate(), 120) -- yyyy-mm-dd hh:mm:ss(24h)
SELECT convert(varchar, getdate(), 121) -- yyyy-mm-dd hh:mm:ss.mmm
SELECT convert(varchar, getdate(), 126) -- yyyy-mm-ddThh:mm:ss.mmm

I am using following in SSRS 2005
=Format(Globals!ExecutionTime,"MM-dd-yyyy" & " ")
& CStr(Hour(Globals!ExecutionTime)) & ":"
& CStr(Minute(Globals!ExecutionTime))
Or
=Format(Globals!ExecutionTime,"MM-dd-yyyy" & " ")
& Right("00" & CStr(Hour(Globals!ExecutionTime)), 2)
& ":"
& Right("00" & CStr(Minute(Globals!ExecutionTime)), 2)
OR:
=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy hh:mm.ss")
OR
=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy HH:mm.ss")

In SSRS 2016 There is an option under the properties header "Localization" called "Calendar", if you click on this it gives you these 2 options:
Gregorian (dd/mm/yyyy)
GregorianUSEnglish (MM/dd/yyyy)
This works brilliantly when referencing data from a tables aswell
alternatively if this does not work for you, specify one of these formats under "Number" and in the cell "Format":
dd/MM/yyyy or MM/dd/yyyy

The following is how I do it using Visual Studio 2017 for an RDL targetted for SSRS 2017:
Right-click on the field in the textbox on the design surface and choose Placeholder Properties. Choose the Number panel and click on Date in the Category listbox, then select the formatting you are looking for in the Type listbox.

If you click on the empty spot on the report away from any table and then look in properties, one of the Misc fields is called Language which allows you to pick which Language you would like to set, which after doing so can play around with this
=FormatDateTime(now,x)
Which x can be 1, 2, 3, 4, 5

If you want date and time separate then use below expressions:
Date and Time Expression
Expression1 for current date : =formatdatetime(today)
its return date is = 11/15/2016
Expression2 for current time : =CDate(Now).ToString("hh:mm tt")
its return time is = 3:44 PM
This report printed on Expression1 at Expression2
Output will be :
Output of Both Expression
This report printed on 11/15/2016 at 3:44 PM

=Replace(Format(CDate(Now()),"MM.dd.yyyy"), ".", "/")

First go to your control panel , select Date , time and Number Format . Now select English(United Kingdom) from the drop down list.
Make sure the shor date field is equal to 'dd/mm/yyyy'. Press Apply. Now go to SSRS and right click on the report in the empty space and select properties.
If you are using visual studio then set Language property equal to =User!Language.
If you are using Report Builder then Language property will appear in Localization section.

hi friend please try this expression your report
="Page " + Globals!PageNumber.ToString() + " of " + Globals!OverallTotalPages.ToString() + vbcrlf + "Generated: " + Globals!ExecutionTime.ToString()

Related

why the date info of minute was wrong after conversion

I used SQL to convert a date:
select date,to_char(date,'yyyy/mm/dd HH24:mm') from process
The original date is 12/5/2018 2:41:06 PM
but the conversion result is 2018/12/05 14:12.
Is my SQL wrong?
mm is the placeholder for the month - regardless of the position. So the second mm contains the month again.
As documented in the manual the placeholder for minutes is mi
So you need: to_char(date,'yyyy/mm/dd HH24:MI')

How to add stored procedure variables to SSRS 2012 Labels

Very new to SSRS so bear with me...
I created an SSRS report based on a stored procedure and as part of that procedure I calculate a StartDate and EndDate for my report. I need to use those two dates in the Title of the report but those variables are not part of the dataset created from the stored procedure.
How do I add those variables to the Title of the report?
Here is the code:
DECLARE #ThisDate date;
SET #ThisDate = getdate(); -- Current date
DECLARE #sdate AS int
SELECT #sdate = CONVERT(int, CONVERT(varchar(10), dateadd(yy, datediff(yy, 0, #ThisDate) - 2, 0), 112)) -- Beginning of previous 2 year
DECLARE #edate AS int
SELECT #edate = CONVERT(int, CONVERT(varchar(10), dateadd(mm, datediff(mm, -1, #ThisDate) - 1, -1), 112)) -- Last Day of previous month
Want my report to display:
From #sdate through #edate ( from 01-01-2014 through 08-31-2016 )
I appreciate the help!
The way you have it now, I would add a SELECT line to use in a dataset:
SELECT #sdate as START_DATE, #edate AS END_DATE
Your expression would have to use a LOOKUP to get the values from the dataset:
="From " & FIRST(Fields!START_DATE.Value, "DataSet1") & " through " & FIRST(Fields!END_DATE.Value, "DataSet1")
HOWEVER, the better way to do what you want is to use SSRS parameters to calculate your START_DATE and END_DATE and then use the parameters when you need the start and end dates.
START_DATE Parameter -
Date Type: DATE
Available Value Expression:
="01/01/" & (YEAR(TODAY) - 2)

SAS PROC SQL String Manipulation

Can I convert a string column formatted as "YYYY-MM" from SQL back into a Date that uses text. (ie. January, 2014) as a new column using proc SQL?
Initially my source is 2014-01 and I would like every row to be converted to the respective month and year as shown. I have tried the Format option outside of the proc SQL table build, however I need it as a Macro date afterwards.
Thanks
Here's one option that uses a custom format. First convert to date using INPUT() with the ANYDTDTE. format. Then you can either display the variable with the format or you can convert it to a new character variable with the format applied.
/*Create your own format definition*/
proc format;
picture monyyc_fmt (default=25)
low - high = "%B, %Y" (datatype=date);
run;
data want;
str='2014-12';
date=input(str,anydtdte.);
format date monyyc_fmt.;
want=put(date, monyyc_fmt.);
put (_all_) (=/);
run;
proc print data=want;
run;
Results are:
Obs str date want
1 2014-12 December, 2014 December, 2014
References for the custom date format:
http://www2.sas.com/proceedings/sugi31/243-31.pdf
Not sure what PROC SQL has to do with the issue of converting the value. One way would be to convert your string to date using INPUT() and then use the CATX(), PUT() and YEAR() functions and the MONNAME. format to build the new string.
data _null_;
str='2014-12';
date=input(str,anydtdte.);
format date date9.;
want=catx(', ',put(date,monname.),year(date));
put (_all_) (=/);
run;
You could skip the middleman and just parse the string yourself to get the year number. This might be easier to code inside an SQL statement.
want=catx(', ',put(input(str,anydtdte.),monname.),scan(str,1,'-'));
In SQL, consider the next example:
-- The table holding the result
CREATE TABLE #myTable(stringDate CHAR(7), dateValue DATETIME, newStringDate VARCHAR(20))
-- The values in original format
INSERT INTO #myTable(stringDate) SELECT '2014-01'
INSERT INTO #myTable(stringDate) SELECT '2014-02'
INSERT INTO #myTable(stringDate) SELECT '2014-03'
INSERT INTO #myTable(stringDate) SELECT '2015-01'
INSERT INTO #myTable(stringDate) SELECT '2015-02'
GO
-- All months have a first day, so conveting "2014-01" to date is just removing "-" and adding "01"
UPDATE #myTable SET dateValue = CAST(REPLACE(stringDate, '-', '') + '01' AS DATETIME)
GO
-- When we have the dates, you can tranform it to the format you want
UPDATE #myTable SET newStringDate = DATENAME(MONTH, dateValue) + ', ' + CAST(YEAR(dateValue) AS VARCHAR)
GO
SELECT * FROM #myTable

BIRT Report: Parameters between two dates

I've got a report I'm writing in BIRT against an Oracle database:
Table:
tranx_no (string)
type (string)
description (string)
amount (number(14,2))
date (date)
Query in BIRT:
SELECT tranx_no, type, description, amount
FROM tranx_table
WHERE date BETWEEN ? AND ?
If I just do plain dates (02-01-2014 and 02-14-2014) in the parameters, it misses things that happen during the day of the 14th (stops at midnight). I've tried concatenating the time onto the date parameter
WHERE date BETWEEN ? || '12:00:00 AM' AND ? || '11:59:59 PM'
and got an ORA 01843 error. I also tried casting it with to_date
WHERE date BETWEEN TO_DATE(? || '12:00:00 AM', 'MM-DD-YYYY HH:MI:SS AM') AND TO_DATE(? || '11:59:59 PM', 'MM-DD-YYYY HH:MI:SS AM')
and no joy there either. ORA 01847 error happens with that one.
Ideas? I know there's probably something simple I'm not thinking of, but Google hasn't helped. I'm wanting to edit the query, not change the date entry on the face of the form.
Thanks.
Correct handling DATEs with BIRT can be tricky.
I recommend to always use VARCHAR2 for passing DATE parameters (for report parameters as well as for query parameters). Always verify the data type of your parameters.
In your SQL, always use TO_DATE / TO_CHAR with an explicit date format - otherwise the results would depend on the locale settings.
Next, be sure that the value the user entered is adjusted to a known date-format before it is used in the query. For example, in Germany the SQL date format DD.MM.YYYY HH24:MI:SS is commonly used.
You could create a utility function which adds the missing parts (e.g. the time) automatically. Use an additional argument in this function to specify if it's a "from" date (adds 00:00:00) or a "to" date (adds 23:59:59).
OTOH if the UI forces the user to enter a from-to date without time (say in the format 'MM-DD-YYYY' as in your example), you could just code
WHERE (date >= to_date(?, 'MM-DD-YYYY') and date < to_date(?, 'MM-DD-YYYY') + 1)
Note the usage of < and not <=.
This works because if no time is specified in the format mask, 00:00:00 (in HH24:MI:SS format) is implied.
As you pointed out the start date is not a problem as it begins at 00:00:00 of the start date. If your paramter is a text box your users can enter 02-01-2014 08:00:00 to get results starting at 8am on Feb 1.
Note that my date format has the year first, while yours has the year last
For the end date, I use a text box paramater with this as my default value
//Creates a date for one second before midnight of the current date,
//which is properly formatted to use as an end date in quires (for my data)
// Note that a custom date format (yyyy-MM-dd HH:mm:ss) is required for proper display in pop-up GUI
var T; T = BirtDateTime.addDay(BirtDateTime.today(),1);
var Y; Y = BirtDateTime.year(T);
var M; M = BirtDateTime.month(T);
var D; D = BirtDateTime.day(T);
{
Y +"-"
+ M +"-"
+ D +" "
+"00:00:00"
}
I also use this help text
Enter date as YYYY-MM-DD. For example, 2013-3-14
Adn this prompt text
End Date (YYYY-MM-DD), if time is blank will default to 00:00:00

SSRS - Oracle DB, Passing Date parameter

Using SSRS with an Oracle Database. I need to prompt the user when running the report to enter a date for report. What is the best way to add in the parameter in my SSRS Report. Having problem finding the right date format. under the "Report Parameter" menu, I have setup the Report Parameters using the DateTime Datatype.
Keep getting this error "ORA-01843: Not a Valid Month"
Thank you for your help.
Select
a.OPR_Name,
a.OPR,
a.Trans_Desc,
a.Trans_Start_Date,
Cast(a.S_Date as date) as S_Date,
Sum(a.Duration) as T
From (
Select
US_F.OPR_Name,
ITH_F.OPR,
ITH_F.ITH_RID,
ITH_F.TRANSACT,
Transact.DESC_1 as Trans_Desc,
To_CHAR(ITH_F.Start_Time,'DD-Mon-YY') as Trans_Start_Date,
To_CHAR(ITH_F.Start_Time,'MM/DD/YYYY') as S_Date,
Substr(To_CHAR(ITH_F.Start_Time,'HH24:MI'),1,6) as Start_Time,
To_CHAR(ITH_F.End_Time,'DD-Mon-YY') as Trans_End_Date,
Substr(To_CHAR(ITH_F.End_Time,'HH24:MI'),1,6) as End_Time,
Cast(Case When To_CHAR(ITH_F.Start_Time,'DD-Mon-YY') = To_CHAR(ITH_F.End_Time,'DD-Mon-YY')
Then (((To_CHAR(ITH_F.End_Time,'SSSSS') - To_CHAR(ITH_F.Start_Time,'SSSSS')) / 60))/60
Else ((86399 - (To_CHAR(ITH_F.Start_Time,'SSSSS')) + To_CHAR(ITH_F.End_Time,'SSSSS'))/60)/60
End as Decimal(3,1)) as Duration
from Elite_76_W1.ITH_F
Left Join Elite_76_W1.Transact
on Transact.Transact = ITH_F.Transact
Left Join Elite_76_W1.US_F
on US_F.OPR = ITH_F.OPR
Where ITH_F.TRANSACT not in ('ASN','QC','LGOT')
) a
Where a.S_Date = #Event_Date
Having Sum(a.Duration) <> 0
Group By a.OPR_Name,
a.OPR,
a.Trans_Desc,
a.Trans_Start_Date,
a.S_Date
Order by a.OPR_Name
Oracle parameters are indicated with a leading colon - #Event_Date should be :Event_Date.
You use CAST(a.S_Date AS DATE) in your query, where a.S_Date is a VARCHAR: To_CHAR(ITH_F.Start_Time, 'MM/DD/YYYY'). If your session date parameter NLS_DATE_FORMAT is different from 'MM/DD/YYYY', this will result in a format error (in your case I suspect your NLS_DATE_FORMAT is something like DD-MON-YYYY, resulting in a "month" error).
A few options:
don't use TO_CHAR in the inner query (always try to keep the date format for internal calculations, use TO_CHAR only where it belongs -- in the GUI). If you only want the date portion, use TRUNC.
use TO_DATE instead of CAST in the outer query: to_date(a.S_Date, 'MM/DD/YYYY'), this is obviously tedious: you cast a date to a varchar that is later transformed to a date.

Resources