Unable to extract week from a date when using variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 08:51 AM
I have a business requirement to extract the week of the year, month and day from a given date in a catalog item. This will be done in a script in a workflow.
However, I'm not getting a value back, just "undefined" and I don't understand why.
Here is my test script:
Does anyone know why it works when I pass it a string but not the variable? I've tried converting the variable to a string, but it doesn't make a difference, it still has the value "undefined".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 08:57 AM
Hi,
You can find as below
var gdt=new GlideDateTime(dateOnly);
gs.info(gdt.getWeekOfYearLocalTime())
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 11:15 PM
Hi @gjz
Considering you will get the date from a catalog variable, you can tweak your existing code as below to make it work :
var dateOnly = new GlideDateTime('2024-01-08');
gs.print('dates: ' + dateOnly);
gs.print('week: ' + dateOnly.getWeekOfYearLocalTime());
This will give you the week number as an output. Here is the output snip for your reference :
Please mark the answer as helpful and correct if it answers your query.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.