cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Dateformat

Test_user
10-Marble

Dateformat

I am getting the date in  DateFormat as  mentioned below
2023-02-09 16:26:07.000
I would need date in this format for ex: 20230209 (YYYYMMDD)format.

 

 

Can you help me out over here ?

 

ACCEPTED SOLUTION

Accepted Solutions
jensc
17-Peridot
(To:Test_user)

Hello,

 

It all depends on what your dataset looks like.

If you have an infotable you'll need to loop through it and format each row at a time.

If you are fetching the data from a database you could do the formatting in SQL instead so you don't waste resources looping.

 

If you only have one value, which is this "CompleteData.ldate", then your code should look like:

 

let yourCSVColumnName = dateFormat(CompleteData.ldate, "YYYYMMDD");

 

The dateFormat function takes two arguments, one is your date variable and the other is the date format you want.

 

However, as I do not know what type your date is in, you can try to do this first:

 

 

let datetime = parseDate("2023-02-05 16:26:07.00", "yyyy-MM-dd HH:mm:ss.SSS");

This will turn a string date into a datetime and you can then pass it into the dateFormat function:

result = dateFormat(datetime, "YYYYMMDD");​

 

 

To help further some more information would be needed, like some error messages or similar.
But I think this covers most of it.
 
Regards,
Jens

View solution in original post

5 REPLIES 5
jensc
17-Peridot
(To:Test_user)

Hello,

 

Where do you need this date format?

In a mashup? If so, in what widget?

 

Regards,

Jens

 

Test_user
10-Marble
(To:jensc)

I have a column named Date in csv file .I would need the date in csv file

jensc
17-Peridot
(To:Test_user)

Hello,

 

Okay, then you should be able to use the "dateFormat" function:

 

result = dateFormat(new Date(), "YYYYMMDD");
 
Where "new Date()" is your date variable.
The resulting value seems to not be compatible with TWX datetime variable type, but should work fine in your csv file as I assume it will translate into a string.
 
Regards,
Jens
Test_user
10-Marble
(To:jensc)

Thank you.

 

instead of new Date()   I have to pass finalResult

 

 finalResult=CompleteData.ldate;            which is in DateFormat(2023-02-05 16:26:07.00)

 

which is not working.

jensc
17-Peridot
(To:Test_user)

Hello,

 

It all depends on what your dataset looks like.

If you have an infotable you'll need to loop through it and format each row at a time.

If you are fetching the data from a database you could do the formatting in SQL instead so you don't waste resources looping.

 

If you only have one value, which is this "CompleteData.ldate", then your code should look like:

 

let yourCSVColumnName = dateFormat(CompleteData.ldate, "YYYYMMDD");

 

The dateFormat function takes two arguments, one is your date variable and the other is the date format you want.

 

However, as I do not know what type your date is in, you can try to do this first:

 

 

let datetime = parseDate("2023-02-05 16:26:07.00", "yyyy-MM-dd HH:mm:ss.SSS");

This will turn a string date into a datetime and you can then pass it into the dateFormat function:

result = dateFormat(datetime, "YYYYMMDD");​

 

 

To help further some more information would be needed, like some error messages or similar.
But I think this covers most of it.
 
Regards,
Jens
Announcements


Top Tags