yyyy-MM-ddT00:00:00 date format in MDX - sql-server

How I can get current date on YYYY-MM-dd (2016-10-28) format in MDX?
Format(Now(),'YYYY-MM-dd')
Doesn't work.
EDIT:
I've just check that MDX convert my YYYY-MM-dd format to yyyy-MM-ddT00:00:00 (I compare my date with current date) so I need something like:
Format(now(), "yyyy-MM-ddT00:00:00")

Never even heard of MDX but with a quick Google search it seems you should use the following format:
Format(Now(),'yyyy-MM-dd')
Notice the lower case y for year.
This information was deduced from here.
After Edit
The new format you want would therefore be:
Format(Now(),'yyyy-MM-ddT00:00:00')

Related

Format a date and time in crystal report

My date is stored in a type date column in dd/mm/yyyy format. I want to print the date in yyyymmdd format.
When i used the following formula
tonumber(totext(db.colname,'YYYYMMDD'))
It gave me a "the string is non numeric" error when previewing the report.
Secondly,
My time is stored in a string column in 12 hour format. I want to display it as hh24miss format.
How do i do that ?
First of all, you should NOT store dates/times as text in your database.
Use the apropriate datatype of your DBMS.
Otherwise you will very likely have further problems because of this.
When you've changed the datatype you could just drag&drop the database-field inside your report and use the formatting options of Crystal Reports to get the desired format.
If for any reason (I doubt there's a good one) you can't change the datatype, use the following formula.
ToText(Date({db.colname}), "yyyyMMdd")
This formula converts the string to a date and then formats the date with yyyyMMdd format.
Notice the uppercase M which is used for the month. Lowercase m is used for minutes.

Snowflake date_trunc to remove time from date

I have snowflake column which contains date in yyyy-mm-dd hh:MM:ss format.
I use the below function
date_trunc('DAY', '2019-09-23 12:33:25')
Output : 2019-09-23 00:00:00
Expected as per documentation : 2019-09-23
Is it a bug or is there any other way to remove the time component altogether ?
Depending on what you're wanting to do with the date, having a midnight time is fine.
If you really must get rid of it, this will work:
cast(date_trunc('DAY', '2019-09-23 12:33:25') as date)
date_trunc as the documentation say, truncates a timestamp to values on different grain. But the result is still a timestamp, thus the output format.
if you want just the truncated date, casting to date as cmcau mentions is a simple way to go. But if you are casting to date there is no need to truncate as they are the same value, thus '2019-09-23 12:33:25'::date should be all you need.
In certain environments like Mode Analytics, casting to date like some of the other answers mention still displays a 00:00:00 on the end. If this is the case and you are only using the date for display purposes, you can take your truncated date and cast it to varchar instead like this: '2019-09-23 12:33:25'::date::varchar
Note, I would only recommend this if the other answers are not working for you.

Creating composite dates from individual year, month, and day in Google Data Studio

I need to create a YYYYMM format computed column for defining a date in Data Studio since our data is held in separate year, month, and day columns. Unfortunately our the month and day fields are not left zero-padded so a simple concat will not work.
The formula I'm using still uses concat, but also uses todate to parse the hyphenated date string into the compatible format.
TODATE(CONCAT(systems.added_year, CONCAT('-', concat(systems.added_month, concat('-', systems.added_day)))), 'DEFAULT_DASH', '%Y%m')
The problem I'm running into, is that Data Studio doesn't seem to correctly recognize the resultant value, even though it seems to be correct. I'm not sure why, but the YYYYMM field seems to one-month behind even though the result of the calculated field looks correct.
In fact it seems 1-day behind, if I show YYYYMMDD the displayed value is the last day of the previous month.
Here is a screenshot showing the component elements, a string version of the calculated field, and then a Date(YYYYMM) version of the calculated field.
Looks like a bug with the output format. As a workaround, you could output as a full date and then change the column format to YYYYMM.
TODATE(CONCAT(year, CONCAT('-', CONCAT(month, CONCAT('-', day)))), 'DEFAULT_DASH', '%Y-%m-%d')
You could also use '-01' as the last segment.

SSRS Date Parameter Mismatching

I have an issue with SSRS where when posting in a DD/MM/YY value via URL string into a Parameter it decides to read the Day value as the Year, the Month as month, but the Year goes into Day value, for example:
I am inputting the date of 30/08/17 via an ERP System which then generates a string to be used as an URL to generate the report, this date value should then go into a parameter called fiAsOfDate which is Date/Time data type, but at this point it is reading the value as 08/17/1930 inside the Parameter list, even though the URL remains at 30/08/17.
This happens prior to the Query being processed, and the fiAsOfDate parameter then gets formatted through to to MMDDYYYY to be processed within the Query, but the issue is specifically when the parameter is having the value loaded from the URL into the parameter value, and I was hoping if anyone could assist me on this please?
I should also add, this original date is coming from an ERP system which will have regional based date formatting, as it is used internationally, so I cannot restrict myself to one input format, and it should be using regional settings, matching that of the Reporting server that it is based on.
Kind Regards,
James W. Acklam.
To avoid regional setting issues you can change the date into a known integer or string format: I use CONVERT(NVARCHAR, YourDate, 112) to get a string '20170830'. The regional settings won't recognize that as a date and so won't auto-parse it into MM/DD/YYYY or DD/MM/YYYY. Of course, you'll need to parse that yourself so you can use it in the report, but at least you know the format.
This issue was down to my own misunderstanding that the DataSource I was pulling data from worked only in DMY format. Converting dates from parameters format to DMY format and processing that through the DataSet's query resolved the issue.

Display date in MM-dd-yyyy format SSRS report

I have a SQL query: select ModifiedDate from Person.Person and this returns the date as 2/24/1998 12:00:00 AM
I'm trying to display this in MM/dd/yyyy format in SSRS report. I have used the expression =Format(Fields!ModifiedDate.Value,"MM/dd/yyyy")
But, still it's coming as 2/24/1998 12:00:00 AM
I want to display this as 2/24/1998.
How can I do this?
I would recommend using the format codes:
Right click - properties on the cell, select format, click the ellipsis "...", and you can see the date formats from there. This will be converted into a date code when you OK the dialog. This is useful as it sets the date in the fomat the user wants to see it in.
To convert the data within SSRS and not the data source you could try using something like:
=Format(Cdate(Fields!ModifiedDate.Value),"dd/MM/yyyy")
Another sample for you without Cdate:
=Format(Fields!ModifiedDate.Value,"dd/MM/yyyy")
There is a special function for formatting Dates in SSRS:
=FormatDateTime(Fields!ModifiedDate.Value, DateFormat.ShortDate)
It will return your date the way that you want it.
As per your question,
To convert the date in SSRS you should try like this,
=FORMAT(Fields!ModifiedDate.Value,"MM-dd-yyyy")
Output would be,
12-06-2010 -- 12(Month)-06(Date)-2010(Year)
Set the language of the entire Report to the language of the country the report is going to be run in.
For example for US it's en_US and for Australia it's en_AU.
Simple !
If you want to get date in format of 'MM/DD/YYYY' use the following query andand you have to convert in varchar datatype.
select CONVERT(varchar(20),GETDATE(),101)
I had this problem and i solve that by this code :
FormatDateTime('MM/dd/yyyy',ADOqueryname.fieldbyname('ModifiedDate').AsDateTime);
I did two things to make it work:
1st, In Data set property Query - select CONVERT(varchar(20),ModifiedDate,101) from Person.Person
2nd, In expression - =Format(Fields!ModifiedDate.Value,"dd/MM/yyyy")
This worked for me.Thanks for the hints.
You can use:
- FormatDateTime(Fields!ModifiedDate.Value, 2)
or:
- FormatDateTime(Fields!ModifiedDate.Value, DateFormat.ShortDate)
You will get the same result.

Resources