cancel
Showing results for 
Search instead for 
Did you mean: 

Start and end date of a week

deepak_shaw
Contributor

Hi,
How to get a start and end date of a week in a single line, I need to use this in a map snap.
Thanks,
Deepak.

1 ACCEPTED SOLUTION

Aleksandar_A
Contributor III

Hi @deepak.shaw

Try the following expression in a Mapper snap:

"Week start: " + Date.now().minusDays(Date.now().getDay()).toLocaleDateString() + " - Week end: " + Date.now().minusDays(Date.now().getDay()).plusDays(6).toLocaleDateString()

The output should look like this:
image

This expression gets the current week start date (Sunday), and the current week end date (Saturday), if you want to consider other days and to modify the output, try changing the expression accordingly.

Let me know if this works for you.

Best Regards,
Aleksandar.

View solution in original post

3 REPLIES 3

deepak_shaw
Contributor

The start of the week (date) in a single line also works for me. Thanks

Aleksandar_A
Contributor III

Hi @deepak.shaw

Try the following expression in a Mapper snap:

"Week start: " + Date.now().minusDays(Date.now().getDay()).toLocaleDateString() + " - Week end: " + Date.now().minusDays(Date.now().getDay()).plusDays(6).toLocaleDateString()

The output should look like this:
image

This expression gets the current week start date (Sunday), and the current week end date (Saturday), if you want to consider other days and to modify the output, try changing the expression accordingly.

Let me know if this works for you.

Best Regards,
Aleksandar.

Hi @AleksandarAngelevski ,
Great solution, In fact, I have implemented it like:

Date.parse(Date.parse($.get('exit_date')).plusDays(-Date.parse($.get('exit_date')).getDay())).toLocaleDateTimeString({"format":"yyy-MMM-dd"})

But your suggestion is better. Thanks, Deepak 🙂