0

I have a week formatted like this: 2023-W12 (for Week 12 in 2023).

I need to get the first day of that week (in this case Monday, 2023-03-20 (yyyy-mm-dd)).

But I can only use plain cfml to achieve this, as of the systems limitation.

I tried dateFormat('2023-W12', 'yyyy-mm-dd') which leads to this error:

The value of parameter 1, which is currently 2023-W12, must be a class java.util.Date value.

Any hints on how I could do this?

Userx10xC
  • 124
  • 9
  • You might have to manually parse out the values using mid(), or a regex to get the parts (year, W??) numbers. Then you can construct a date, see if it's Monday, if not, loop by -1 until you find a Monday. There are math options as well.... I know you can output a week-based format, but not sure if you can parse a date with it....) – Will Belden Mar 22 '23 at 16:12

1 Answers1

1

You can try using the parseDateTime function.

var date = parseDateTime( '2023-W12', "YYYY-'W'w");
// date is {ts '2023-03-19 00:00:00'}
etchesketch
  • 821
  • 4
  • 14
  • IT seems you're looking for the first *Monday*, as opposed to the first day of the week (Sunday)? If so, what @etchesketch suggested will work but it gives you the date of the Sunday of the week in question. So, simply add a day like so: #adate#
    #firstMondayOfWeek#
    – CFMLBread Mar 22 '23 at 18:06
  • 1
    yeah in germany we have monday as first day of the week :-) thx to both of you, that did work perfectly! – Userx10xC Mar 23 '23 at 11:33