Date Conversion

Blitz3D Forums/Blitz3D Beginners Area/Date Conversion

Mental Image(Posted 2004) [#1]
I need to be able to convert a date in this format:

"04/10/05" (YY/MM/DD)

to this format:

"Fri 02-13-2004" (Day MM/DD/YYYY)

I can do the string manipulation easily enough, but does anyone know of a simple way of working out what DAY something occured on based solely on the date? I could use a lookup table, I'm sure, but an algorithm taking account of leap years (and millenia!) would be nice!

Thanks,

Paul


_PJ_(Posted 2004) [#2]
To do any form of working out with dates, I would assume the best thing to do would be to convert it to an integer first.

This might help

It's a bit early and my brain hasn't been jumpstarted yet, but Ill have a think on it.


soja(Posted 2004) [#3]
I would use GetDate (kernel32). An example:
;.lib "Kernel32.dll"
;GetDate%(iLocale%, iFlags%, iDate%, iFormat$, oDate$, iSizeBuf%):"GetDateFormatA"
;GetDateAny%(locale%, dwFlags%, lpDate*, lpFormat$, lpDateStr$, size%):"GetDateFormatA"

day$ = String(" ", 150)
GetDate(0, 0, 0, "d dd ddd dddd M MM MMM MMMM y yy yyyy gg", day, Len(day))
Print day

time = CreateBank(16)
PokeShort(time, 0, 2004) ; Year
PokeShort(time, 2, 4) ; Month
PokeShort(time, 6, 17) ; Day
GetDateAny(0, 0, time, "ddd MM-dd-yy", day, Len(day))
Print day



_PJ_(Posted 2004) [#4]
Oryou can use userlibby things and get all technical and cheaat if ya know how unlike us poor thickos wot cant even spell propper :)

Is this like a BlitzPlus thing?
How do userlibs work?

Good stuff soja!


soja(Posted 2004) [#5]
=)

Well, basically you define a line in a decls file (in your userlibs folder) which tells Blitz how to call an exported function from a DLL. This one uses a DLL (kernel32.dll) that's part of Windows (from Win95 on). Here, the commented lines at the top need to go in the decls file.

Then you can call the function according to the parameters it expects. In this case, I found them out from msdn.microsoft.com -- I looked up GetDate.

It works in the latest version of Blitz3D and BlitzPlus.


_PJ_(Posted 2004) [#6]

fine a line in a decls file (in your userlibs folder)


Lost me already but Il not worry about it now - this thread's been hijacked enough :/


Mental Image(Posted 2004) [#7]
Thanks guys for all your help.


Oldefoxx(Posted 2004) [#8]
Many date routines have been written and should be available for copying or download. Some people consider the
leapyear problem, but suprisingly, others do not.

However, there is also a 100-year and 400-year rule for handling leapyears (100-year dates like 1800 and 1900 are not leapyears, while 1600 and 2000, divisible by 400, are leapyears).

Going forward, even these adjustments are imprecise. There is some reason to consider a 500-year and a 2000-year rule, and when you try to justify 20,000 year intervals, you begin having to think about the fact that the earth is slowing down in its rotation (longer days) and its orbit wobbles enough to make its orbit around the sun take different paths and lengths of time.

If that seems excessive, it likely is. A lot of people only want to reason time over a few years or a few decades. For that purpose, you may not need an elaborate algorythm to get a good count of days between two dates. All dates from March 1, 1900 to February 28th, 2099 are only suseptable to the 4-year yeapyear rule, and you can go from year 1 to close to 20,000 with just the 4-year, 100-year, and 400-year rules. That is probably far longer than today's civilizations will endure. (which is good, since we've already missed four 500-year and one 2000-year adjustments, so at some date in the future, our calendars are going to be off by a few days, assuming we last that long).


Mental Image(Posted 2004) [#9]
Your last paragraph is very important, and you are right - I am certainly only looking at dates that go back a few years. However, wasn't there some controversy over whether the year 2000 was a leap year or not?