Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Remove Time From Date

Author  Topic 

pcride
Starting Member

9 Posts

Posted - 2011-09-27 : 23:03:59
Hi, I have a column in SQL actually, assuming the commands would be the same in Access. I have a Created Date field and its Date and Time.

I have my basic query

Select * FROM DATABASE name
[Column Names],
[Column Names],
[Column Names],
[Created Date]

How do I write the query to format the date as Date without the time using

a) select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)

or

CAST(FLOOR(CAST(getdate() AS FLOAT)) AS DATETIME)

??

pcride
Starting Member

9 Posts

Posted - 2011-09-27 : 23:22:13
Looks like I figured it out!
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-09-27 : 23:25:02
you are using SQL Server 2008 or Access ?

if it is SQL 2008, there are 2 ways to do it depends on what is the end data type that you want.


declare @dt datetime

select @dt = getdate()

select [date] = convert(date, @dt), [date time] = dateadd(day, datediff(day, 0, @dt), 0)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -