Solved

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

Posted on 2009-05-12
4
3,269 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
ID: 24369921
select convert(varchar(30),getdate(),101)
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 84 total points
ID: 24369922
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
ID: 24370235

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
ID: 24856736
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

821 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