Solved

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

Posted on 2009-05-12
4
3,291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 41

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In T-SQL cursor convert smallint to varchar 15 51
Creating a SQLServer BI cube from Oracle data source 4 42
ms sql and asp dates 5 42
Use SSRS to email customers? 4 29
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

734 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