T-sql date question

pts.
Tags:
SQL
Does anyone know how I can convert 2005-09-14 09:49:13.873 to 2005-09-14 00:00:00.000 in a query?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Try function:

CONVERT ( data_type [ ( length) ] , expression [ , style ] )

see:

http://www.databasejournal.com/features/mssql/article.php/2197931

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Chicotellez
    try this. sql server 2000 /* Creating a Test Table */ Create Table MyDateTest99 ( DateColumn smalldatetime ) go /* Inserting the test value into the table */ /*insert into MyDateTest99 values ('2005-09-15 00:00:00') */ insert into MyDateTest99 select convert (varchar(10),'2005-09-15 01:03:22',120) go /* Selecting the result */ select DateColumn from MyDateTest99 go /* Performing Cleanup */ drop table MyDateTest99 go
    0 pointsBadges:
    report
  • LeChuck
    At first I went for the same solution as first mentioned by servee, but for some reason, my SQL Server did not return the needed. I doubt, that the solution by chicotellez would work, unless your database runs certain languages, that by default removes the hh.mm from the smalldatetime. - hh.mm is normally part of the smalldatetime! Besides - creating an entire new table just to solve this problem seems a bit like shooting birds with canons! Since the solution by servee didn't work for me, I worked out this solution in stead... Not an optimal solution at all - I admit to that - but it works: declare @date as datetime, @strDate as varchar(10) set @date = getdate() set @strDate = cast(day(@date) as varchar) +'-'+ cast(month(@date) as varchar) +'-'+ cast(year(@date) as varchar) select cast(@strDate as datetime) Hope someone has a better solution! (?) Good luck Jacob
    0 pointsBadges:
    report
  • Denny Cherry
    Use the convert function.
    select convert(varchar(10), '2005-09-14 09:49:13.873', 101)
    66,130 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following