I need to check a date/time field is "before now",...
# suiteanalytics
n
I need to check a date/time field is "before now", I will be doing this in code but want to avoid using a javascript date object as I'm seeing unexpected results. Can anyone advise, through the UI is fine, what I can add to the criteria to check this please? (cannot be "before today" has to include the time. Thanks.
b
you can try converting them both to dates so that when you subtract them, you get a number
id rather try and get the javascript date working rather than do something ugly with formulas
n
No, not's not what I mean. I have a scheduled script runs every 15 mins. I only want results where the date/time on the records is "before now"
I'm not looking for an ugly formula I'm hoping there's a before "now" like before "today"
@al3xicon actually looks like you were doing something similar
a
hey @NElliott I was trying to calculate the time (hours) elapsed between a custom date/time field on a support case and "now" ({today})
so if you used something like that in your saved search criteria that drives your scheduled script, i'd assume it would work
it's just
({today} - {customfield}) * 24
or should be anyway
but for whatever reason it doesn't quite work with custom fields the way it does with native date/time fields, so you ave to wrap your
{customfield}
in a TO_DATE(TO_CHAR())
and just use the same format for date/time, i used
MM/DD/YYYY HH24:MI
but i don't think it matters as long as it's consistent and contains both date and time. i did find that using
HH24
is necessary as just
HH
is problematic for obvious reasons...probably OK to include the AM/PM char in there too but i didn't try it
n
@al3xicon Thank you very much for replying that's very helpful, appreciated.
a
cheers no problem
n
I was trying to compare the datetime "now" i.e when the script is started, with a date/time field on an SO. The reason being, the field on the SO can be in the future. As it turns out it was another search criteria that was throwing up "unexpected" behaviour 😑Eventually I go to the bottom of it. This is still very useful information you provided, I'll bank it 👍
a
right on - i'm sure you'll come across this issue before long!