Office Automation Date, PB equivalent of it?

Just starting out? Need help? Post your questions and find answers here.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Office Automation Date, PB equivalent of it?

Post by djes »

Thunder93 wrote:LOL!!! Thanks for the laugh! :lol:
djes wrote:I really think that using floating numbers for date/time is crazy. Never I would have created such a thing. Just imagine that this kind of function could be used for planes or banking data makes me mad ! :evil:
:wink: :mrgreen:
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Office Automation Date, PB equivalent of it?

Post by Thunder93 »

I only got down to the day, then I'm stumped... I told you I suck at math, but here Is what I have thus far. :lol:

Code: Select all

Debug "Our Goal: 09/09/2016 06:03:51"+#CRLF$
OADoubleValue.s = "42622.25267361111"

OADaysFROM1900 = Int(Val(OADoubleValue))
OAMilSecsFROM1900 = Val(StringField(OADoubleValue, 2, "."))

Year.l = OADaysFROM1900 / 365 : Debug "Year: "+Str(Year+1900)
Month.l = Year / 12 : Debug "Month: "+Month
Day.l = (OAMilSecsFROM1900 / 86400000) / 30  : Debug "Day: "+Day
Thunder93 wrote:I was working on a cross-platform DateTime formula. My math sucks, ....
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Office Automation Date, PB equivalent of it?

Post by djes »

I don't think it could be that easy, as years are not always 365 days long, and months not always 31 days long, and don't forget the particular years where time has to be corrected... It could be a correct formula as long as it converts intervals in days, but getting the correct date from 1900 I doubt !

Edit

I found a lot of links about this oddity.

The best and funniest ones :
https://blogs.msdn.microsoft.com/ericli ... o-vt_date/ and especially this one (linked) : https://www.joelonsoftware.com/2006/06/16/my-first-billg-review/

Some useful with links :
http://stackoverflow.com/questions/7348 ... javascript
http://stackoverflow.com/questions/1055 ... at-in-ruby
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Office Automation Date, PB equivalent of it?

Post by Thunder93 »

I don't think that the leap year is a problem in this case, to retrieve the years.

since 1 January 1900, 42705 days past, brings us now onto 2017.

Code: Select all

OADaysFROM1900.d = 42705.0
Debug OADaysFROM1900 / 365
Debug (OADaysFROM1900 / 365) + 1900
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Office Automation Date, PB equivalent of it?

Post by djes »

Yes, but if you have to determine what year (not especially 2017) it was around dec 31, you surely will have problems sometimes...
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Office Automation Date, PB equivalent of it?

Post by Thunder93 »

Yes... wayyyy to much variables. It's a shame PureBasic Date library doesn't support Microsoft Date. :lol:
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Office Automation Date, PB equivalent of it?

Post by blueb »

Thunder93

not sure if this helps...

Code: Select all

;==================================================================
;
; Author:   wayne-c      
; Date:        Jan 29, 2007
; Explain:   http://forums.purebasic.com/english/viewtopic.php?p=180010&sid=6515b4e0c9eb795c8d96c9f62903c187#p180010
;           
; Typical Usage:   convert   VariantTimeToSystemTime to date     
;==================================================================
Import "oleaut32.lib"
  VariantTimeToSystemTime(d.d, lpSystemTime.l)
EndImport
vt.d= 39111.5032638889
st.SYSTEMTIME
If VariantTimeToSystemTime(vt, @st)
  d.d= Date(st\wYear, st\wMonth, st\wDay, st\wHour, st\wMinute, st\wSecond)
  Debug FormatDate("%dd.%mm.%yyyy %hh:%ii:%ss", d)
EndIf
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Office Automation Date, PB equivalent of it?

Post by Thunder93 »

Already had that covered. Thanks though :)

http://www.purebasic.fr/english/viewtop ... =4&t=67953
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Post Reply