[dba-SQLServer] SQL Server date functions

Elizabeth.J.Doering at wellsfargo.com Elizabeth.J.Doering at wellsfargo.com
Tue Mar 18 13:06:38 CDT 2008


John,

Select myfield from mytable where mydatefield > getdate()-1 

Pulls everything in the last 24 hours.

You could come up with more elegant variations with dateadd or datediff
to get exactly the correct number of hours.

HTH,


Liz 


Liz Doering 
elizabeth.j.doering at wellsfargo.com 
612.667.2447 


This message may contain confidential and/or privileged information. If
you are not the addressee or authorized to receive this for the
addressee, you must not use, copy, disclose, or take any action based on
this message or any information herein. If you have received this
message in error, please advise the sender immediately by reply e-mail
and delete this message. Thank you for your cooperation.


-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, March 18, 2008 12:50 PM
To: 'Discussion concerning MS SQL Server'
Subject: [dba-SQLServer] SQL Server date functions

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
http://www.databaseadvisors.com






More information about the dba-SQLServer mailing list