I'm trying to add 1 millisecond to date using dateadd function (Sybase ASE) but have no luck in this:
select dateadd(ms, 1, getdate()) cur_date,
dateadd(ms, 1, getdate()) add_ms,
datediff(ms,dateadd(ms, 1, getdate()), getdate()) diff_ms
cur_date: 2018-06-21 12:54:20.360
add_ms: 2018-06-21 12:54:20.360
diff_ms: 0
Can you please help to find solution for this?
The datetime type has accuracy of 1/300 second. If you want to get a next value add 3 or 4 ms to the value you have.
The alternative is to cast to bigdatetime type (accuracy 1 microsecond = 1/1000000 s) and then add the 1ms. Try:
select dateadd(ms, 1, convert(bigdatetime, getdate())) cur_date,
dateadd(ms, 1, convert(bigdatetime, getdate())) add_ms,
datediff(ms,dateadd(ms, 1, convert(bigdatetime, getdate())),
convert(bigdatetime, getdate())) diff_ms
diff ms: -1