Jump to content

Day of the year


F.vant.Hoff

Recommended Posts

I want to write a script that will rename a file with in the name the day of the Year. The original name is JOURNAAL.DAT and it must be renamed to JYYYYDAYofYEAR.001 (ex. On 15 June 2006 the name will be J2006166.001 because June 15 is 166th day of the year). How can I calculate in VBScript that number, the day of the year?thanks for helping me out.

Link to comment
Share on other sites

  • 1 month later...
Try this....<%dim strDateTimestrDateTime = Now()strPastDay = #01/01#%><%=INT(strDateTime - strPastDay) %>
I believe if you subtract 01/01 from the date today you will get the wrong Julian date. Example: if you subtract jan 1 from jan 15, you get 14, however jan 15 is the 15 day of the year!So:strDateTime = Now() + 1 would seem to be the answer as 01/00 will give you an error.
Link to comment
Share on other sites

  • 4 weeks later...

I think you have to calculate the day of the year from the current date. To do that, your have to write a function that gives the number of days for each month of the year regarding the bissextile years. Then write a function to determine which day of the year is the first day of the month based on the preceding one.Finally, calculate the day of the year regarding the difference between the day of the month and the first day of the month.

Link to comment
Share on other sites

I think you have to calculate the day of the year from the current date. To do that, your have to write a function that gives the number of days for each month of the year regarding the bissextile years. Then write a function to determine which day of the year is the first day of the month based on the preceding one.Finally, calculate the day of the year regarding the difference between the day of the month and the first day of the month.
Frankly the day of the year is referred to as the "Julian Date", and since 01/01/xx is the first day of the year, not the zero day of the year, you can simply just subtract the current date from 01/01/xx and it will give you the Julian date--BUT-- it will be off by one day. So you need to place a fix: Now() + 1, because if you subtract 0 from any number you will generate an error in code. You are going at it too hard. The code language knows how many days there are in each month, so you don't have to factor that in. It knows when the year is a leap year too by the simple rule: it is a leap year if the year is divisible by 4, no remainder, except if it divisible by 100, no remainder, except if it is divisible by 400, no remainder. See pretty much everything you mention is already taken care of in the code language that u use. :)
<script language="VBScript"><!--MyYear = "1/1/" & Right(Year(Now),2)DiffADate = "Julian Date: " & DateDiff("d", MyYear, Now) + 1document.Write(DiffADate & "<br />")//--></script>

Run this script and check against this web site:http://daac.gsfc.nasa.gov/julian_calendar.shtml><> ><> ><> ><> ><> ><> ><> ><> ><>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...