Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Jul 23, 2017 9:43 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: CDbl(DateTime) in RealBasic
PostPosted: Tue Jun 05, 2012 12:38 am 
Offline

Joined: Sat May 05, 2012 11:04 pm
Posts: 11
Location: PH
Okay, so How do i do this in RealBasic?..

A_Date = Date with time ex. 2012/06/05 1:06:32 PM

Converting date to double in VB6 is easy like this

Dim dVal as Double
dVal = CDbl(A_Date)


Now how can I do it in RealBasic?

I saw something like this when im searching google so I tried it.

Dim dVal as Double
dVal = A_Date.TotalSeconds


But it they don't produce the same value

Hoping for your respond,

Thanks,

_________________
My Website
http://silentprojectsoftwares.com/
Programming Language
Visual Basi 6.0 SP6 (Primary)
Real Studio 2011r4 (Still Testing)
Development Machine
Windows XP SP3
Other OS using VMWare
Windows XP SP2, Windows Vista, Windows 7 (32 and 64), Ubunto Linux, Max OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Tue Jun 05, 2012 2:47 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Quote:
But it they don't produce the same value

Why is that a problem?

A date is a date.
You can compare dates, or you can compare totalseconds. Still works.

The way in which a date is stored varies by language, platform...
Apple has used 1/1/1970 as a 'ground zero' at one point.
Other systems (Excel, Office) use 1/1/1900 as the ground zero.

As long as you are working in 'recent history' and use actual dates, you don't need to know or care about the underlying storage method (integer, Float, string...)

Read a date. Write a date.
Going to the double sounds like mistake.

But if you insist, see if the difference between the value you get from total seconds differs by 1970 years worth of seconds.


Also see this post:
viewtopic.php?f=1&t=35119&hilit=1970


Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Tue Jun 05, 2012 4:29 am 
Offline

Joined: Sat May 05, 2012 11:04 pm
Posts: 11
Location: PH
kermit wrote:
Quote:
But it they don't produce the same value

Why is that a problem?

A date is a date.
You can compare dates, or you can compare totalseconds. Still works.

The way in which a date is stored varies by language, platform...
Apple has used 1/1/1970 as a 'ground zero' at one point.
Other systems (Excel, Office) use 1/1/1900 as the ground zero.

As long as you are working in 'recent history' and use actual dates, you don't need to know or care about the underlying storage method (integer, Float, string...)

Read a date. Write a date.
Going to the double sounds like mistake.

But if you insist, see if the difference between the value you get from total seconds differs by 1970 years worth of seconds.


Also see this post:
viewtopic.php?f=1&t=35119&hilit=1970


They don't produce the same value so that is my problem.. haha..

I am converting a vb6 source that plays with date and when I come up with that line, i don't know how should I do it in RealBasic.

_________________
My Website
http://silentprojectsoftwares.com/
Programming Language
Visual Basi 6.0 SP6 (Primary)
Real Studio 2011r4 (Still Testing)
Development Machine
Windows XP SP3
Other OS using VMWare
Windows XP SP2, Windows Vista, Windows 7 (32 and 64), Ubunto Linux, Max OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Tue Jun 05, 2012 4:54 am 
Offline
User avatar

Joined: Thu Aug 26, 2010 6:57 am
Posts: 569
Location: Sydney Australia
TotalSeconds will get you the number of seconds since 12:00AM, January 1, 1904 in RS. The reason it is different to VB is because they use a different reference date.
If you want to use the reference date from VB in RS you will have to get the latest date totalseconds and subtract the earlier date (VB's ref date) totalseconds.

Dim dateVB as new Date(1970,1,1) // When is VB's ref date?
Dim dateNow as new Date // Date is equal to creation date
Dim intSeconds as Integer

intSeconds = dateNow.TotalSeconds - dateVB.TotalSeconds

MsgBox CStr(intSeconds) // Or whatever you want to do with the value

_________________
Regards

Chris Musty
http://www.specialised.net.au
-----------------------------------------------
if date.shortdate >= 4/6/2013 then
msgbox "I am using Xojo - YAY!!!"
else
msgbox "I am still using RS 12r2.1 - BOO!!!"
end if

Win 8 Pro, Ubuntu 13.04, Mint and Debian(gnome and KDE)
AWS for Hosting and TKL for AMI's


Last edited by Specialised on Tue Jun 05, 2012 6:21 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Tue Jun 05, 2012 5:08 am 
Offline

Joined: Sat May 05, 2012 11:04 pm
Posts: 11
Location: PH
Specialised wrote:
TotalSeconds will get you the number of seconds since 12:00AM, January 1, 1904 in RS. The reason it is different to VB is because they use a different reference date.
If you want to use the reference date from VB in RS you will have to get the latest date totalseconds and subtract the earlier date (VB's ref date) totalseconds.

Dim dateVB as new Date(1970,1,1) // When is VB's ref date?
Dim dateNow as new Date // Date is equal to creation date
Dim intSeconds as Integer

intSeconds = dateNow.TotalSeconds - dateVB.TotalSeconds

MsgBox CStr(dblSeconds) // Or whatever you want to do with the value


:D Thanks, Im going to try this out.

_________________
My Website
http://silentprojectsoftwares.com/
Programming Language
Visual Basi 6.0 SP6 (Primary)
Real Studio 2011r4 (Still Testing)
Development Machine
Windows XP SP3
Other OS using VMWare
Windows XP SP2, Windows Vista, Windows 7 (32 and 64), Ubunto Linux, Max OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Fri Jun 08, 2012 12:08 am 
Offline

Joined: Sat May 05, 2012 11:04 pm
Posts: 11
Location: PH
Can you help me again?..

The return value of doubles shows as scientific notation like this 3.416735e+9, now how can I fix this?..

_________________
My Website
http://silentprojectsoftwares.com/
Programming Language
Visual Basi 6.0 SP6 (Primary)
Real Studio 2011r4 (Still Testing)
Development Machine
Windows XP SP3
Other OS using VMWare
Windows XP SP2, Windows Vista, Windows 7 (32 and 64), Ubunto Linux, Max OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Fri Jun 08, 2012 12:17 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Use the Format( theNumber, "0.000000000000000") command.


Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Fri Jun 08, 2012 8:25 am 
Offline

Joined: Sat May 05, 2012 11:04 pm
Posts: 11
Location: PH
kermit wrote:
Use the Format( theNumber, "0.000000000000000") command.


Okay, Thanks,

_________________
My Website
http://silentprojectsoftwares.com/
Programming Language
Visual Basi 6.0 SP6 (Primary)
Real Studio 2011r4 (Still Testing)
Development Machine
Windows XP SP3
Other OS using VMWare
Windows XP SP2, Windows Vista, Windows 7 (32 and 64), Ubunto Linux, Max OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: CDbl(DateTime) in RealBasic
PostPosted: Fri Jun 08, 2012 3:28 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
jhai_salvador wrote:
But it they don't produce the same value

Specialised wrote:
When is VB's ref date?


Quote:
(The Date type) Holds IEEE 64-bit (8-byte) values that represent dates ranging from January 1 of the year 0001 through December 31 of the year 9999, and times from 12:00:00 AM (midnight) through 11:59:59.9999999 PM. Each increment represents 100 nanoseconds of elapsed time since the beginning of January 1 of the year 1 in the Gregorian calendar. The maximum value represents 100 nanoseconds before the beginning of January 1 of the year 10000

http://msdn.microsoft.com/en-us/library ... 80%29.aspx

If the above applies to the question at hand, it would seem that the problem comes from RB counting TotalSeconds and VB counting 100ns intervals; if this is the case then the VB code would give a number 100,000 times larger than RB if they had the same epoch. Given that the RB Date class' epoch (12:00 AM, January 1, 1904CE) is nearly two thousand years later, this would also contribute to vastly different results.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group