Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
smpa01
Super User
Super User

SQL Native Query for extracting DATE portion

Hello Experts,

 

I have a a SQL table with a column called CreatedDate. The native data type is datetime (known through Table.Schema). It looks as following once I connect to the table  with following SQL custom statement

 

Capture.JPG

 

 

select [$Table].[CreatedDate]  as [CreatedDate]
       
     from [dbo].[X] as [$Table]
   

 

Now all I want is the column value to feature as only DATE without any time like following

 

CreatedDate
6/1/2016
7/14/2016
2/18/2016

 

after reading some blog posts I tried the following

 

select CONVERT(VARCHAR(10), [$Table].[CreatedDate], 110)  as [CreatedDate]
       
     from [dbo].[X] as [$Table]
   

Code 1

 

Outout 1Outout 1

select CAST ([$Table].[CreatedDate] as DATE) as [CreatedDate]
       
     from [dbo].[X] as [$Table]

Code 2

 

Output2Output2

select CONVERT(DATE, [$Table].[CreatedDate])  as [CreatedDate]
       
     from [dbo].[X as [$Table]

Code3

Output3Output3

The probelm here is CODE 1 turns the output to a Text value whereas CODE 2 and 3 keeps the value as DATE but brings the time too 12:00:00 AM.

 

Can I use a SQL code which helps me extract only the date part and yet the data type detected by PBI as DATE after the SQL execution.

 

Thank you in advance.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @smpa01 ,

 

Actually, code2, code3 already suitable for your requirement.
It only extract date part from your datasource, you only need to change the column type to date to remove blank time part.(12:00:00 AM equal to 0:00:00)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.