Sql date/ time help
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

[Closed] Sql date/ time help

9 Posts
6 Users
0 Reactions
44 Views
Posts: 0
Free Member
Topic starter
 

If I want to test if a date/time is greater than 4am yesterday how would I go about doing it in sql?


 
Posted : 29/01/2015 12:31 pm
Posts: 0
Free Member
 

check for anything greater than todays date Minus 20hrs


 
Posted : 29/01/2015 12:42 pm
Posts: 349
Free Member
 

datediff maybe( not sure if that's t-sql specific)? Do you need to consider timezones at all?


 
Posted : 29/01/2015 12:44 pm
Posts: 0
Free Member
Topic starter
 

to_char(start_date, 'YYYYMMDDHH24MISS') > to_ char(sysdate-1,'YYYYMMDD')||'040000'

works. I was sure I'd tried that before asking the question but must have had an error somewhere 🙂


 
Posted : 29/01/2015 1:20 pm
Posts: 0
Free Member
 

easier:

your_date > DATEADD(hh, -20, CAST(CAST(GETDATE() AS DATE) AS DATETIME))


 
Posted : 29/01/2015 1:25 pm
Posts: 0
Free Member
 

to_char(start_date, 'YYYYMMDDHH24MISS') > to_ char(sysdate-1,'YYYYMMDD')||'040000'

Hang on, did you just call to_char on every record in the table? this is a one off right?

/not an SQL guy


 
Posted : 29/01/2015 1:47 pm
Posts: 0
Free Member
Topic starter
 

No use for Oracle though 🙂


 
Posted : 29/01/2015 1:49 pm
Posts: 0
Free Member
 

ah, scope creep... 😆


 
Posted : 29/01/2015 1:50 pm
Posts: 0
Free Member
 

Would something like this work?

create_date >= TO_DATE('28/01/2015 04:00:00.000000','MM/DD/YYYY HH24:MI:SS.FF')

/still not an SQL, let alone an oracle, guy


 
Posted : 29/01/2015 1:53 pm
Posts: 401
Free Member
 

create_date >= CURRENT_DATE - INTERVAL '1 DAY' + INTERVAL '4 hours'


 
Posted : 29/01/2015 2:14 pm

6 DAYS LEFT
We are currently at 95% of our target!