I'm receiving today date from a server side script...
# suitescript
a
I'm receiving today date from a server side script: 23/09/2020 How can I convert it to 2020-09-23
e
A video on how to add moment js to your script (by @erictgrubaugh)

https://www.youtube.com/watch?v=BlUqPUI9ALo

❤️ 1
e
Naturally I put that video out right as moment is announcing they're shifting to maintenance mode. https://momentjs.com/docs/#/-project-status/
a
Thanks
Can we use setDate method on the object we are receiving from a server side script?
@ericbirdsall @erictgrubaugh Could you please let me know how moment can help, this is the exact format that I want: Iso string 2020-09-23T093000
e
It can help because it's a library for parsing and formatting dates: https://momentjs.com/docs/#/displaying/format/
a
Yes that's correct
But even with moment I'm receiving a completely different time
For example
b
where are you getting your value from
a
Server side search
Inside a suitelet script
b
most of the time that will be a string in the current user's timezone
a
Correct
How can I convert it to
Iso
2020-09-23T093000
Something like this
b
in what timezone do you want that string
a
User time zone
b
that is actually the harder answer
a
So I will do the conversion in the same script
Let's say GMT
To make it easier
I think I can find the user time zone and set it later
b
GMT is easy since a Date has built in support for that. Use format.parse to turn your string into a Date
a
Ok and then
b
use toISOString to turn the strings into a iso8601 datetime string
by default thats in UTC
a
The pare type is Datetimez?
b
It will not be that simple if you want different timezones
a
It says
Property toisostring doesn't exist on type string | number | date
After parse
I've set the parse type to Datetimez
b
what does your code look like
a
Format.Parse({ value: res.getValue('time'), type: Datetimez, Timezone: 32 })
. toisostring ()
b
a lot of that looks invalid
go through the documentation i sent
a
Which one
b
both
a
Why
Parse
Is invalid
It's the same as documents
b
not what you pasted
a
I'm getting the right value after parse
But I can't attach toisostring method to it
b
if your code works, then you arent pasting what you are using in here
in which case the help i offer is limited to saying that your spelling is wrong
a
The only difference is type
Which is
Format.Type.Datetimez
Here is some typing difficulty
That's why I've made it shorter
b
case matters, i cant tell if your code isnt working because you are spelling wrong, or if your inputs are wrong
a
The spelling are 100% correct
The output of parse is the same as grtValue method
23/09/2020
b
Format.Parse should fail because its parse and not Parse
a
Yes parse
That's my stupid phone
Will change it to capital
As I said
The result of parse
Is the same as getValue method
b
format.parse is hard to work with because if you put in invalid parameters, it outputs the input value
a
23/092020
Ah
Timezone is correct
Right
32
Maybe I need to change type
b
23/09/2020 is not datetime
there is only a date in there
a
The issue is when I change it to DATE
It will complain
No overload matches this call
b
cant help you there without the code
if you are still specifying 32 as the timezone, 32 is not a valid timezone
a
Ah
What's the valid one for GMT
b
you dont want to specify it at all
the parameters to format.parse are describing your input string
your string is not GMT
a
"2024-09-21T030000.000Z"
Value from parse
24/09/2020
Value from getValue
I've deleted the timezone
And change type to
DATE
Parse code
format.parse({ value: test, type: Type.DATE, })
And test is
From getValue('time')
Inside search
Which is 24/09/2020
b
sounds like there is a dateformat mismatch
what search type are you using
a
Search type?
b
what does your search object look like
a
There is always problem with date object
Do you recommend any good document that can help with that
Type: 'phonecall'
b
what column are you getting values from
a
Startdate
b
what the date format from the user preferences of the user using the suitelet
a
I don't have access to it now I'm out of office
How that can help
b
N/format will use the current user's preferences when parsing dates, which would be the preferences of the current user
for the strings you are sharing, that format should be DD/MM/YYYY
a
What if we don't want to relay on that
And have something fix
Oh so if another user
b
however the way format.parse is working is assuming the format is YYYY/MM/DD
a
With different preference
Run the script
The result from parse will be different?
b
the point of using N/format is that it defaults to using the current user's preferences
however what you are sharing contradicts that
dont know where the mismatch is without knowing your code / user preferences
a
So how we can parse and don't use current user's preferences
b
at that point i would say to use moment, which is a more general date manipulation library