SQL converting datetime to shortdate
by Rizo on apr.20, 2009, under Developing
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.
[sourcecode language=’sql’]
DECLARE @latestDate as datetime
SET @latestDate = (SELECT postDate from table where postDate = (Select max(postDate) from table))
[/sourcecode]
This will return Jan 20 2009 6:45PM
Then all I need to add to my SELECT is
[sourcecode language=’sql’]
CONVERT(VARCHAR(10), @latestDate, 101)
[/sourcecode]
This will return 01/20/2009
2 Comments for this entry
20 Trackbacks / Pingbacks for this entry
-
หวยหุ้นดาวโจนส์
oktober 3rd, 2023 on 00:11… [Trackback]
[…] Read More Information here to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
superkaya88
november 18th, 2023 on 09:50… [Trackback]
[…] Find More on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
dk7
december 3rd, 2023 on 01:13… [Trackback]
[…] Information to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
ราคาบอลวันนี้
december 18th, 2023 on 01:19… [Trackback]
[…] Read More to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
ประตูสำเร็จรูป
december 23rd, 2023 on 01:20… [Trackback]
[…] Read More here to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
สีทนไฟ
april 19th, 2024 on 02:02… [Trackback]
[…] Find More on on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
Highbay
maj 2nd, 2024 on 01:03… [Trackback]
[…] Here you will find 60228 additional Information on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
Highbay
juni 27th, 2024 on 00:16… [Trackback]
[…] Find More here to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
url
juli 11th, 2024 on 12:38… [Trackback]
[…] Read More Information here on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
พนันออนไลน์ เล่นที่ไหน เมื่อไหร่ก็ได้
juli 25th, 2024 on 23:44… [Trackback]
[…] There you will find 47044 more Info on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
บริษัทรับทำเว็บไซต์
augusti 24th, 2024 on 23:08… [Trackback]
[…] Find More Info here to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
รับจด อย
augusti 25th, 2024 on 01:03… [Trackback]
[…] Find More here on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
เว็บสล็อตหมีแพนด้า
augusti 29th, 2024 on 23:38… [Trackback]
[…] Information on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
เช่ารถตู้พร้อมคนขับ
oktober 13th, 2024 on 09:21… [Trackback]
[…] Find More Information here on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
once human cheat
oktober 13th, 2024 on 11:46… [Trackback]
[…] Read More Info here on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
Web Site
oktober 14th, 2024 on 00:24… [Trackback]
[…] Read More Information here on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
ข้อดี – ข้อเสีย Sbobet Mobile Login
oktober 14th, 2024 on 12:13… [Trackback]
[…] Find More to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
Sbobetclub168
oktober 18th, 2024 on 03:18… [Trackback]
[…] Find More on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
บาคาร่าเกาหลี
oktober 22nd, 2024 on 06:09… [Trackback]
[…] Read More Information here to that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
-
บริการรับสร้างบ้าน
oktober 25th, 2024 on 04:41… [Trackback]
[…] Info on that Topic: from-rizo.se/sql-converting-datetime-to-shortdate/ […]
juli 13th, 2009 on 17:15
wow you really help me, thanks
oktober 20th, 2009 on 21:40
I put the convert directly into my sql statement
SELECT CONVERT(Varchar(11), DateColumnName), COLUMN2, COLUMN3
FROM XYZ
WHERE ConditionHere
I had to use 11 chars because it comes back like this:
Jan 01 2009