Link to home
Start Free TrialLog in
Avatar of weklica
weklica

asked on

Day of Year in XSL Sheet

I have the following XSL which gives me 'dow' as 0-6 which I can call later on (see below).
I need the same sort of code which will also allow me to call 'doy' for day of year.  So, October 31st would result as 305 or something similar.  January 1st would be a 1.  

Any guidance on this would be great.  
Thanks

	<xsl:template match="/dataset">
		<dataset>
			<xsl:variable name="year" select="number(substring($date, 1, 4)) "/>
			<xsl:variable name="month" select="number(substring($date, 5, 2)) "/>
			<xsl:variable name="day" select="number(substring($date, 7, 2)) "/>
			<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
			<xsl:variable name="y" select="$year - $a"/>
			<xsl:variable name="m" select="$month + 12 * $a - 2"/>
			<!-- 0-6, where 0=Sunday. -->
			<xsl:variable name="dow" select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>

Open in new window

Avatar of Bill Prew
Bill Prew

Try this:


There are also some good functions shown on this page, and while one doesn't do exactly what you need, it would be easy to use the same technique as above and get the Julian day number, and subtract the Julian day number of the 1st day of that year, then add 1.  Take a look at the section "4.4. Calculating Julian and Absolute Day Numbers from a Specified Date" as a starting point.



»bp
Here my proposal:
<xsl:template match="/">
		<dataset>
			<xsl:variable name="date" select="//dataset/date" />
			<xsl:variable name="year" select="number(substring($date, 1, 4)) "/>
			<xsl:variable name="month" select="number(substring($date, 5, 2)) "/>
			<xsl:variable name="day" select="number(substring($date, 7, 2)) "/>
			<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
			<xsl:variable name="y" select="$year - $a"/>
			<xsl:variable name="m" select="$month + 12 * $a - 2"/>
			<!-- 0-6, where 0=Sunday. -->
			<xsl:variable name="dow" select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>			
			<xsl:variable name="n1" select="floor((275 * $month) div 9)"/>			
			<xsl:variable name="n2" select="floor(($month + 9) div 12)"/>
			<xsl:variable name="n3" select="(1 + floor(($year - 4 * floor($year div 4) + 2) div 3))"/>
			<!-- 0-356, days since January, 1st -->
			<xsl:variable name="doy" select="$n1 - ($n2 * $n3) + $day - 31"/>

Open in new window

The formula name is Zeller's congruence:
https://astronomy.stackexchange.com/questions/2407/calculate-day-of-the-year-for-a-given-date
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of weklica

ASKER

Wonderful. I will test this out tonight when I am near the station. Thanks much!
Hello weklica, did you have the opportunity to test my formula?
Avatar of weklica

ASKER

Zvonko's solution was exceedingly helpful!   Thanks much!!!!
You are welcome  :  )