I know this is the SuiteScript space but wondering...
# suitescript
j
I know this is the SuiteScript space but wondering if anyone can validate if this is a valid query? SELECT * FROM customer WHERE TO_CHAR(TO_DATE(datecreated, 'MM/dd/yyyy'),'yyyyMM') = 201811 we're having issues querying this from another platform that's authenticated to NetSuite...
b
its valid in some accounts, but invalid in others
you are essentially converting a date to a char, then back to a date, then back to a char
with that first date to char being implicit
TO_DATE works on chars, so your datecreated is converted to a char first, using the user's date format setting
those date format settings can be different between users
skip the messiness and just convert the date to a char once
j
@battk Thanks! I will suggest this to the consultant
m
@JC Please use below.
Copy code
SELECT * FROM customer WHERE TO_CHAR(datecreated, 'yyyyMM') = '201811'
💯 1
There is no need to convert datecreated to date type, because it's already date type.
And also, the TO_CHAR function returns string type, so the comparison value must be string type, not integer type
j
@Mark Oriend Thanks! I'll give this a try