Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
day/month to date converter...
#1
Anyone have a day/month to date converter? :-)

e.g.: X day of Y month = N date of the year.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#2
Not the most straightforward way, but no one answered it....


DOY(y,m,d)=julian(y,m,d)-julian(y,1,1)+1

and julian date is:

Code:
Function tojulian&(y,M,D)
  'From Egbert Zijlema  ABC packets 1996
  temp& = (M  - 14) \ 12
  JulPart& = D  - 32075 + (1461 * (Y  + 4800 + temp&) \ 4)
  JulPart& = JulPart& + (367 * (M  - 2 - temp& * 12) \ 12)
  tojulian& = JulPart& - (3 * ((Y  + 4900 + temp&) \ 100) \ 4)
end function
With a little patience you could rework it and remove everything that cancels in the substraction and get a simpler formula.

y=year ,m=month number, d=day of month

Hope it helps!
Antoni
Reply
#3
pseudo-code:
Code:
function getDayOfYear( day, month )

    int[] days_elapsed_per_month = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
    return day + days_elapsed_per_month[ month ];

end function

This has the assumption that February always has 29 days, which is necessary for days of different years to match up properly (e.g. the 10th of March will always be day 90, regardless of whether it's a leap year or not).
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#4
Running that code you supplied returns a value which seemingly makes no sense at all...

Code:
declare function tojulian&(y,M,D)


print tojulian&(2006,09,29)

sleep
end

Function tojulian&(y,M,D)
  'From Egbert Zijlema  ABC packets 1996
  temp& = (M  - 14) \ 12
  JulPart& = D  - 32075 + (1461 * (Y  + 4800 + temp&) \ 4)
  JulPart& = JulPart& + (367 * (M  - 2 - temp& * 12) \ 12)
  tojulian& = JulPart& - (3 * ((Y  + 4900 + temp&) \ 100) \ 4)
end function

...and the result:
Quote:2454008

Can you explain this to me please? I am working on an answer to this solution, too, Agamenmus. Although being an experienced coder, you'd probably know how to do it anyway. But I could be wrong. Tongue

EDIT:
http://www.qbasicnetwork.com/stuff/yeardate.bi

Code:
'#include: "yeardate.bi"

converttodate(2000,1,1)

Enjoy.
Screwing with your reality since 1998.
Reply
#5
C# has all that functionality built in :p Check the msdn.

VB.net should have it as well cosidering it is comptaible with all C#'s functions...
b]Hard Rock[/b]
[The Stars Dev Company] [Metal Qb flopped] [The Terror]
Stop Double Posts!
Whats better? HTML or Variables?
Reply
#6
Anarky:
Yes , today's julian date is 2454008, as you can check here http://aa.usno.navy.mil/data/docs/JulianDate.html

Julian date is a "date serial" of the same kind VB or FB uses. The only difference is the position of the origin. VB's 0 is 0hAM of December 30,1899, while julian date starts ar noon of January 1, 4713 BC (don't ask me why, it's used for astronomical calculations ).

The idea was to substract today's serial from january 1's serial. Obviously in VB or FB you could use the built-in date serial.
Code:
#include "vbcompat.bi"
doy=dateserial(y,m,d)-dateserial(y,1,1)+1
Antoni
Reply
#7
Ah, I see...

I'm working on another function to go with this program. It will be able to count the number of days passed given any two dates from any two years assuming the calendar is current the whole time.

I wonder if this could be included in FB's library package?
Screwing with your reality since 1998.
Reply
#8
Code:
declare function tojulian&(y,M,D)


later = tojulian&(2006,09,30)
earlier = tojulian&(1981,08,06)

totaldays = later - earlier
print totaldays
sleep
end

Function tojulian&(y,M,D)
  temp& = (M  - 14) \ 12
  JulPart& = D  - 32075 + (1461 * (Y  + 4800 + temp&) \ 4)
  JulPart& = JulPart& + (367 * (M  - 2 - temp& * 12) \ 12)
  tojulian& = JulPart& - (3 * ((Y  + 4900 + temp&) \ 100) \ 4)
end function

So simple... and here I was trying to make a 200 line long routine to do this...
Screwing with your reality since 1998.
Reply
#9
In FB you can use DateDiff
EVEN MEN OF STEEL RUST.
[Image: chav.gif]
Reply
#10
Mrmm.. I used FB's date functions after writing my own.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)