CAMPzxzxDeathzxzx
asked on
UTC millisecond Cast DateAdd Hours error
How should I write this to get anything older than 3 hours?
WHERE TimeStamp > CAST(DATEDIFF(SECOND, '19700101', DATEADD(hh, -3, CAST(GETDATE() AS date))) AS bigint) * 1000
ASKER
I don't understand?
ASKER
How should I write this?
ASKER
WHERE [TimeStamp] < DATEADD(ms, -10800000, GETUTCDATE())
Now I don't understand. Is TimeStamp a true datetime column or it elapsed ms since 1970-01-01 (unix style date)?
If it's a datetime, then, yes, I would think your last style of code would be right.
If it's a datetime, then, yes, I would think your last style of code would be right.
ASKER
The TimeStamp is UTC milliseconds. I do not have this working yet. The error is "Arithmetic overflow error converting expression to data type datetime"
ASKER
This is the first time I've worked with UTC and you can tell I just don't get it. Yes - Is TimeStamp a true datetime column or it elapsed ms since 1970-01-01 (unix style date)?
Please help - this is the last piece to put this to bed.
Please help - this is the last piece to put this to bed.
ASKER
elapsed ms since 1970-01-01 (unix style date)
ASKER
Please
ASKER
here's my current attempt
WHERE TimeStamp >= CAST(DATEDIFF(SECOND, '19700101', DATEADD(hh, -3, CAST(GETDATE() AS date))) AS bigint) * 1000
ASKER
The datepart hour is not supported by date function dateadd for data type date.
The statement has been terminated.
The statement has been terminated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This project is a 60 day sprint with a $$bonus if I complete on time. To say I'm a little ragged right now is an understatement. Sorry for making a mess of this one!
I've got it working now - I think! Notice the <= instead of >= and also I had to compensate for my server's location in -5 UTC zone.
I've got it working now - I think! Notice the <= instead of >= and also I had to compensate for my server's location in -5 UTC zone.
WHERE TimeStamp <= CAST(DATEDIFF(SECOND, '19700101', DATEADD(hh, -8, GETUTCDATE())) AS bigint) * 1000
ASKER
Thanks
CAST(DATEDIFF(SECOND, '19700101', DATEADD(hh, -3, GETDATE())) AS bigint) * 1000