How  to calculate the day of the year
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 04:13 PM
How to calculate the day of the year
like
Today Tuesday October 24, 2023 is ...
Day 297
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 11:27 PM
Hi,
Here is one way to do it. Take the difference between the day and the first day of the year and add one day.
var sgd1 = new GlideDate(); 
sgd1.setDisplayValue('2023-01-01'); 
var sgd2 = new GlideDate(); 
sgd2.setDisplayValue('2023-10-24'); 
 
var duration = GlideDate.subtract(sgd1, sgd2);
var dayNumber = parseInt(duration.getDisplayValue())+ 1;
 
gs.info(dayNumber);
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 05:34 AM
This code works. But i need to have the year changed dynamically,Instead of hard coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 11:34 PM
Try this piece of code:
OUTPUT::
*** Script: Today is Day 297
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 05:35 AM
with GlideDateTime can we achive this instead of date
