Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert GETDATE()

Status
Not open for further replies.

boyley

IS-IT--Management
Aug 19, 2004
2
GB
In search of SQL to obtain "yesterday's" begin/end times for a batch process:

GETDATE() needs to be converted to Yesterdays FIRST and LAST second:
------- --------------------------------
2001-06-25 14:23:56.054 ---> 2001-06-24 00:00:00.001 (1st sec. of yesterday)
2001-06-25 14:23:56.054 ---> 2001-06-24 23:59:59.999 (last sec. of yesterday)

Will CAST and/or CONVERT fucntions assist? The follwoing SQL returns GETDATE()-1 (yesterday along w/ a time) I need the time converted to 1st and last second...

declare @date_time_accessed datetime,
@DateAccessed varchar(80),
@TimeAccessed varchar(80)

select convert(varchar(10),getdate()-1,120) as dateaccessed,
convert(varchar(8),getdate()-1,114) as timeaccessed
 
Try something like this:

dMyStartDate =
cast( left(getdate() -1 , 10) + ' 00:00:00' as datetime ) Robert Bradley
Sr. DBA, some big company
cheap prints and oil paintings:
 
Hi there,
Hope this will give you desired result.

--------------------------------
select convert(datetime,convert(char(10),dateadd(dd,-1,getdate()),102)+' 00:00:00.001' ) as datebegin,
select convert(datetime,convert(char(10),dateadd(dd,-1,getdate()),102)+' 23:59:59.999' ) as dateend
--------------------------------


 
try

where datediff(dd,neededDate,getDate())<=1
[color]
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top