Set Date to 1st of Current Month

I am trying to get the current date and convert it to the 1st of the current month of the current year.
The resulting format should be dd/mm/yyyy

SnapLogic doesn’t recognize this expression (even without the Date.parse):

Date.parse(Date.now().withDayOfMonth(1)+"/"+Date.now().getMonth()+"/"+Date.now().getFullYear()),"\ddMMyyyy")

Where am I going wrong with the syntax?

1 Like

Hi @NAl ,
Try this expression

Date.now().withDayOfMonth(1).toLocaleDateTimeString({"format": "dd/MM/yyyy"})
3 Likes

Hi @j.angelevski,

SnapLogic doesn’t recognise it. Here is the error message: Call of parse([dateStringOrEpochTimestamp[, format]]) is missing a closing parentheses. Intermediate result is: "NaN""

@NAl , I just tried this expression myself in a Mapper and it works as expected. Make sure you copied the expression properly because the error message is telling you that you are missing a closing parentheses.

My bad, you’re right. I just saved and validated the pipeline. Looks like it’s accepted it and the output date is the 01/07/2021.

This is a much cleaner and simpler expression than mine!