[dba-SQLServer] Dates and times

David Lewis David at sierranevada.com
Tue Mar 18 14:09:08 CDT 2008




John:  You need to strip the time portion off the date, then convert it back to a date, then do your compare.

For example:

DECLARE @dt DATETIME
SET @dt = ' 2008-03-24 10:19:02'
SET @dt=CONVERT(DATETIME,(CONVERT(VARCHAR, at dt,112)))
PRINT CONVERT(VARCHAR, at dt)

This will return  Mar 24 2008 12:00AM

The 12:00AM is the default time for any date that has no time associated with it.  When you do your compare of today's date with the date in the table, you will have to transform both dates as above.




I am pulling a TopN kind of thing and marking those records with GetDate()
which places a date and time in a date field.  Now I want to pull all the
records with today's date.  The first problem is that GetDate() pulls the
date and time.  The second problem is what to place in the filter.  I am not
finding a date() kind of thing like you have with Access.

How do I pull all records with today's date in a date field (that also
contains the time)?

John W. Colby
Colby Consulting
www.ColbyConsulting.com



------------------------------

_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver


End of dba-SQLServer Digest, Vol 61, Issue 10
*********************************************

The contents of this e-mail message and its attachments are covered by the Electronic Communications Privacy Act (18 U.S.C. 2510-2521) and are intended solely for the addressee(s) hereof. If you are not the named recipient, or the employee or agent responsible for delivering the message to the intended recipient, or if this message has been addressed to you in error, you are directed not to read, disclose, reproduce, distribute, disseminate or otherwise use this transmission.  If you have received this communication in error, please notify us immediately by return e-mail or by telephone, 530-893-3520, and delete and/or destroy all copies of the message immediately.




More information about the dba-SQLServer mailing list