Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 



How can I convert a SQL date/time to just date?

RSS
Subscribe to Windows IT Pro | See More SQL Server and Database Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

A. The SQL date/time field stores a date and time but if you have a populated table and you want to convert a column so it lists data only run the following:

update <table>
where <column>=convert(datetime,convert(char(10),<column>,101))

For example

update faq
where created=convert(datetime,convert(char(10),created,101))


End of Article



Reader Comments
I think this is incorrect... its supposed to be:

convert(<datatype to conver to>, <field>, <style>)

so.. if I have a field called transactiondate then my sql is:
select convert(char(10), transactiondate, 101) as Dates from mytable

or if you had birthdays in a table you wanted to query...

select name, age from birthdays where convert(char(10), transactiondate, 101) = '01/04/1970'

Christopher Conner November 02, 2000


I'm sorry but your syntax is completely wrong.

update faq
where created=convert(datetime,convert(char(10),created,101))


You're missing the SET keyword and your column would not have the right results. Say for instance you have a date 1/1/2000 11:00:00 PM. Your code would produce, first of nothing, but if it were fixed it would produce 1/1/2000 1 which would be seen as 1/1/2000 1:00:00 AM.

Daniel Janik March 06, 2001


It should be:
update <table>
set <column>=convert(datetime,convert(char(10),<column>,101))

Björn Österman April 07, 2001


Hi there !
I am using SQL 6.5 , my problem is , I am passing two dates into a stored procedure. My stored prcedure looks like this

CREATE PROCEDURE rep1air_tk(@Debtor_no int,
@Date1 varchar(11),
@Date2 varchar(11))

AS

declare @sql1 varchar(255),
@sql2 varchar(255),
@sql3 varchar(255),
@sql4 varchar(255),
@sql5 varchar(255),
@sql6 varchar(255),
@sql7 varchar(255)





select @sql1 = ' select '
select @sql2 = ' b.collect_dt,b.car_grp,b.Days'
select @sql3 = ' a.inv_crn_no ' + ' from'
select @sql4 = ' rep1debtrans'+ convert(char(6),@Debtor_no)+ ' a ' + ', rep1car'+ convert(char(6), @Debtor_no)+ ' b'
select @sql5 = ' Where a.inv_crn_no = b.inv_crn_no '
select @sql6 = ' and a.collect_dt >= "'+ convert(varchar(11),@Date1) +'"'
select @sql7 = ' and a.collect_dt >= "'+ convert(varchar(11),@Date1) +'"'

exec(@sql1+@sql2+@sql3+@sql4+@sql5+@sql6+@sql7)

This work well when I call my stored procedure from isql/w ,
from vb it gives run-time error '-2147217900(80040e14)'
[Microsoft][odbc sql server driver]
[sql sever] invalid column name 'feb 03 2000'

and my sqlString from vb looks like this

sqlString = "rep1air_Tk " & Dbt_no & "," & "'feb 03 2000'" & "," & "'jan 31 2001'"

Set rsTemp = objCon.Execute(sqlString)

Thanking you in advance

Kenneth

Kenneth April 18, 2001


Which is the date format ?

dd/mm/yyyy or mm/dd/yyyy

into the condition ?

Solino Giuseppe June 01, 2001


How i can insert mutlple rows in table like in oracle &colname

ahmed June 29, 2001


How can I convert a date format to mm/yyyy.

And where is there a listing of style to use such as 101.

Charlie Gomez August 29, 2001


I can't get this to work I get an error statement

Jarod October 04, 2001


Where do I input this statement? Do I add this into "Constraint expression"?

Mike November 12, 2001


How can i convert a sql datetime into a date, using MSQUERY, for Excel 97?

Bru CARLONI February 21, 2002


 See More Comments  1   2 

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
No Jobs, No Excitement at Apple's Last Macworld Keynote

Apple CEO Steve Jobs made the right move in skipping out on his company's last appearance at Macworld: In a Tuesday keynote address at the conference, Apple had no interesting new products to sell, opting instead to spend mind-numbing amounts of time on ...

Where is Microsoft NetMeeting in Windows XP?

...

The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...


SQL Server and Database Whitepapers StoreVault SnapManagers for Microsoft Exchange and SQL Server

Related Events Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Cloud Computing Forum: Integrating Software, Server and Storage as a Service into Your Enterprise IT Delivery Model

Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Check out our list of Free Email Newsletters!

SQL Server and Database eBooks Safeguarding Your Windows Servers

SQL Server Administration for Oracle DBAs

Taking Control: Monitoring the Windows Platform Proactively

Related SQL Server and Database Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing