Follow @Lusse3 (117 followers)

Flickr Recent Photos

Sen är det fika på #valtech :)God lunch med @mohseno2010-03-08 010Fikar med Sara @ vete katten#biltema bjuder på slushies idag :)Fick tag på nå billig cigarr :)Länge sen man unna sig det här, men Inter - Chelsea är värt detÄr det ok att fota sin rotfyllning? :)Vilken dag!Lost och gotta! :)det verkar som om det är ok med 99 liv. Liam körde på iskallt ;) så du slipper fundera på det nu @JoopeyHärlig present! :)

Categories

SQL converting datetime to shortdate

I’ve a table where I need to select the posts with the latest date. Problem is that when you get the latest date it also gets it by the hour, meaning that it will try to fetch everything older or equal to the date + time, which is nothing. There for, I need to make it a shortdate so I can fetch everything that was posted on that day.

The following code will set the variabel to the latest date on the table.

DECLARE @latestDate as datetime
SET @latestDate = (SELECT postDate from table where postDate = (Select max(postDate) from table))

This will return Jan 20 2009 6:45PM

Then all I need to add to my SELECT is

CONVERT(VARCHAR(10), @latestDate, 101)

This will return 01/20/2009

2 comments to SQL converting datetime to shortdate

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>