Skip to main content
10-Marble
February 10, 2023
Solved

Dateformat

  • February 10, 2023
  • 1 reply
  • 2494 views

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 ?

 

Best answer by jensc

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

1 reply

17-Peridot
February 10, 2023

Hello,

 

Where do you need this date format?

In a mashup? If so, in what widget?

 

Regards,

Jens

 

Test_user10-MarbleAuthor
10-Marble
February 10, 2023

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

17-Peridot
February 10, 2023

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