1161
Views
5
Comments
Solved
Text to date with different format
Question

Hi,

I have some issues with date which I get through API as text like this "05/27/1995 12:00:00 AM" I tried all of the built-in functions like FormatDateTime, Replace / to -  and so on. Every time it retunes the null date like "1900-01-01 00:00:00".  Is there something which can help me to get the correct date like "1995-05-27 00:00:00"


2021-03-18 21-03-15
Benjith Sam
 
MVP
Solution

Hi Nabi,

Unfortunately, I'm not aware of any forge asset that addresses your requirement. Defining a custom logic/solution is the other option which you can opt, as Gee suggested.

If the DateTime value format from the API remains the same on all occurrences then you can also try the below-mentioned implementation.

Implementation Steps: 

  1. Using substr() in-built function, extract the date value
  2. Split the Date text value with / as delimiter, using the String_Split function referenced from Text Extension
  3. Mend the Date text value, from the split function return value in a default date format yyyy-mm-dd
  4. Using the TextToDate() conversion function, convert the text Date value to Date data type value

Demo screen: FormatDateTimeToDateTask

Refer to the attached oml.

I hope this helps you!


Kind regards,

Benjith Sam

Sparkle_FormatDateTimeToDate_Task.oml
2021-03-18 21-03-15
Benjith Sam
 
MVP

Hi Nabi,

I presume that, you want the API's response DateTime text converted Date value in the screen scope. One of the approaches would be to use JS.

JS Snippet:

var dt = new Date($parameters.DateTimeText);
$parameters.DateText = dt.getFullYear() + "-" + (dt.getMonth() + 1) + "-" + dt.getDate();

Demo screen: FormatDateTimeToDateTask

Refer to the attached oml.

I hope this helps you!


Kind regards,

Benjith Sam

Sparkle_FormatDateTimeToDate_Task.oml
2023-05-28 08-12-17
M.Nabi

Hi Sam, 

Thank you for your response this approach is for client action what is I am using server Action because we don't have JS in server action.


2021-03-18 21-03-15
Benjith Sam
 
MVP
Solution

Hi Nabi,

Unfortunately, I'm not aware of any forge asset that addresses your requirement. Defining a custom logic/solution is the other option which you can opt, as Gee suggested.

If the DateTime value format from the API remains the same on all occurrences then you can also try the below-mentioned implementation.

Implementation Steps: 

  1. Using substr() in-built function, extract the date value
  2. Split the Date text value with / as delimiter, using the String_Split function referenced from Text Extension
  3. Mend the Date text value, from the split function return value in a default date format yyyy-mm-dd
  4. Using the TextToDate() conversion function, convert the text Date value to Date data type value

Demo screen: FormatDateTimeToDateTask

Refer to the attached oml.

I hope this helps you!


Kind regards,

Benjith Sam

Sparkle_FormatDateTimeToDate_Task.oml
2022-07-24 08-50-37
Gokula Kannan P

Hi @M.Nabi,

there is an alternate way to convert the DateTime string and am not sure this will be the best practice. But am sure this solution will help you to resolve the issue. 

you can re-struct the regex format which requires as per your scenario.


2023-05-28 08-12-17
M.Nabi

Thank you, Kay, 



Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.