Converting String to Date Format

I need to convert the string in date time format as ‘MM/dd/yyyy’. How to do that? Suppose String date = ‘2022-09-15’ I need to convert it as date – 09/15/2022. I tried with parseDateTimeUTC method but it’s not giving correct output.  
3 answers

Hi, you can parse the string to datetime and then format is as string again if you need another format.

So in your case it would be:

Let’s say your string variable is called DateInput 

parseDateTime($DateInput, "yyyy-MM-dd”) 

Let’s name that variable ParsedDateTime

then you could do formatDateTime($ParsedDateTime,””dd/MM/yyyy”)

Or do it at once:

formatDateTime(parseDateTime($DateInput, "yyyy-MM-dd”) ,””dd/MM/yyyy”)


documentation can be found here: Parse & Format Date Function Calls | Mendix Documentation


Hi Sonam,


As Jord said, first convert your date string to desired string format using the one shared by jord

Jord Code:

$formattedString = formatDateTime(parseDateTime($DateInput, "yyyy-MM-dd”) ,””dd/MM/yyyy”)


The above will give you the result as a string but u need it in date time format right. Then,


Pass the above code result to parseDateTime again like this


parseDateTime($formattedString, "dd/MM/yyyy”) 


What Jord said, but if you’re sure the input has the format yyyy-MM-dd and you want to stay away from datetime handling you could use CommunityCommons.RegexReplaceAll with following parameters:

Haystack: $DateInput or whatever you string variable is called

Needle regex: ‘(\d{4})-(\d{2})-(\d{2})’

Replacement: ‘$3/$2/$1’