This worked for getting the difference between two...
# suitescript
c
This worked for getting the difference between two dates last week:
ABS(TO_DATE({created},'MM/dd/yyyy HH:mi:ss')- TO_DATE({now},'MM/dd/yyyy HH:mi:ss')) * 60 * 24
. This week it's returning an error? Anyone else run into this?
I dunno what changed, but this change works now:
ABS(TO_DATE(TO_CHAR({created},'MM/dd/yyyy HH:mi:ss'),'MM/dd/yyyy HH:mi:ss') - TO_DATE(TO_CHAR({now},'MM/dd/yyyy HH:mi:ss'),'MM/dd/yyyy HH:mi:ss')) * 60 * 24
It's just recasting the date into a format the
TO_DATE
function likes again.
b
TO_DATE works on character strings, and neither created nor now are character strings
so it implicitly converts it to a character string, which will by default use the user's date and time settings
which makes it vulnerable when those settings dont actually match what you said they were in the format you specified in TO_DATE
👍🏻 1
c
Key takeaway "which will by default use the user's date and time settings".
Don't implicitly trust things that move. 🙂
b
might actually be the database's format setting, but same idea
im not actually sure why you are using TO_DATE or TO_CHAR in the first place
you can just subtract the two expressions
c
I tried that initially but I want the difference in minutes.
Last week {created} returned
MM/dd/yyyy HH:mi:ss
, this week I get back
MM/dd/yyyy HH:mi AM/PM
, which
TO_DATE
doesn't seem to like.
b
as in ({now} - {created}) * 60 * 24
the absolute isnt needed since now is always going to be after created
and the TO_CHAR and TO_DATE are just converting a date into a char back into a date
c
I'll try ({now} - {created}) * 60 * 24 and see if it's the same
b
taking another look at this, you probably want to take a much closer look at your time format, HH is the 12 hour format, which means you are essentially losing 12 hours in the pm
watching following 2