Solved

Update query to remove time from date/time stamp field in SQL Server table

Posted on 2009-05-12
4
3,231 Views
Last Modified: 2012-05-06
I have a table in SQL server, in which I have a field called 'date', which has a date/time format. I want to write an update query to leave the date in ther, but remove the time stamp from the field.

So this,

DATE
1/12/2009 1:12:07 AM
1/15/2009 3:45:03 PM

becomes this:

DATE
1/12/2009
1/15/2009

Thanks.
0
Comment
Question by:super786
4 Comments
 
LVL 31

Assisted Solution

by:James Murrell
James Murrell earned 83 total points
Comment Utility
select convert(varchar(30),getdate(),101)
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 84 total points
Comment Utility
the datetime field stores both date and time, even if you try to store the date alone there, it will append the '00:00;000' as the time

UPDATE urTable
SET urDateColumn = CONVERT(Varchar(8), urDateColumm, 112 )
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 83 total points
Comment Utility

As aneeshattingal said, by default datetime type will have both the date and timestamp values.
You can get rid off the timestamp with CONVERT function for display purpose but it will internally store the timestamp for any date. If no timestamp, then it will be defaulted to 00:00:00
so alter the table to add a column of varchar type, then update newly added column with aneeshattingal solution or any other value which ever format you want.
http://msdn.microsoft.com/en-us/library/ms187928.aspx
0
 
LVL 2

Expert Comment

by:TejasShahMscIT
Comment Utility
Hi,

You can also this,
UPDATE      tbl
SET            DateColumn = DATEADD(dd,0, DATEDIFF(dd,0,DateColumn))

This will make date: "2009-07-14 02:00" to "2009-07-14 00:00"

Let me know if it helps you.

Thanks,

Tejas
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now