Solved

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

Posted on 2009-05-12
4
3,256 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on t-sql 2012 10 53
2016 SQL Licensing 7 40
always on switch back after failover 2 32
ms sql + get number in list out of total 7 26
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

776 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