cancel
Showing results for 
Search instead for 
Did you mean: 

Set Date to 1st of Current Month

NAl
Contributor

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 ACCEPTED SOLUTION

j_angelevski
Contributor III

Hi @NAl ,
Try this expression

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

View solution in original post

4 REPLIES 4

j_angelevski
Contributor III

Hi @NAl ,
Try this expression

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

NAl
Contributor

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""

j_angelevski
Contributor III

@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.

NAl
Contributor

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!