Access to DateTime Structs

berndgoedecke

Active Member
Licensed User
Longtime User
Hello,
is it possible to access the DateTime Structs, Methods etc.(DateTime-Member (System)) with the Door Library or is a special DateTime Libraray needed to convert VB2005- or B4P-Date to other formated DateTime Typs like Borland TDateTime ?

best regards

berndgoedecke
 

berndgoedecke

Active Member
Licensed User
Longtime User
Hello Erel,
I need a Method to convert to Borland TDateTime, because I had a Look at SQLite-Expert, the program you advise in a Thread about SQLite.
This program casts TDateTime as a Formated Date-String. Also Filippos ListView is able to cast a TDateTime Value as a formated String. So it should be nice to have a conversion Method, without handling a lot of binary operations.

Best regards

berndgoedecke
 

agraham

Expert
Licensed User
Longtime User
From Googling
In Delphi, TDateTime is a type that maps to a Double. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of the TDateTime value is fraction of a 24 hour day that has elapsed.Following are some examples of TDateTime values and their corresponding dates and times:


0 12/30/1899 12:00 am
2.75 1/1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/1/1996 12:00 am
In B4ppc a DateTime is a double representing the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001.

So
B4X:
Sub App_Start   
   Msgbox(TicksToTDateTime(TimeAdd(DateParse("01/01/1900"),18,0,0)))
   Msgbox(TicksToTDateTime(TimeAdd(DateParse("01/01/1996"),0,0,0)))
   Msgbox(Date(TDateTimeToTicks(2.75)) & " " &  Time(TDateTimeToTicks(2.75)))
   Msgbox(Date(TDateTimeToTicks(35065)) & " " &  Time(TDateTimeToTicks(35065)))   
End Sub

Sub TicksToTDateTime(ticks)
   dt = ticks - DateParse("12/30/1899") ' change date start
   days = Int(dt/cTicksPerDay)
   dayfraction = (dt Mod cTicksPerDay) / cTicksPerDay 
   Return days + dayfraction
End Sub

Sub TDateTimeToTicks(TDateTime)
   Return TDateTime * cTicksPerDay + DateParse("12/30/1899")
End Sub
 

berndgoedecke

Active Member
Licensed User
Longtime User
Hello Agraham,
first thank you for the reply. After googeling the TDateTime Type, my first intention was similar to yours: Convert the String to a double Value and the appearance in SQLite-Expert and ListView should be ok.
But the following happens:
Have a look at the first jpg: There is shown how the value is put to the table.
The second jpg shows the DateTime-value(Lieferdatum) in the ListView.
The third jpg shows the DateTime-value(Lieferdatum) in SQLite-Expert, but it has been interpreted as a 0 value (1899-12-30)
In the fourth jpg the values(Lieferdatum) are changed by using SQLite-Expert.
The fifth picture shows the changed values in the ListView.
And I wonder !
Where is the difference, are there different Mantisse-Bits in the double ?
Or is there another mistake ?

best regards

berndgoedecke
 

Attachments

  • Double_ListView.jpg
    Double_ListView.jpg
    10.3 KB · Views: 222

agraham

Expert
Licensed User
Longtime User
The third jpg shows the DateTime-value(Lieferdatum) in SQLite-Expert, but it has been interpreted as a 0 value (1899-12-30)
It seems to be Versanddattum that is zero in the third jpg, not Lieferdatum. All the Lieferdatum entries seem to be consistent and accurate, as are the Betelldatum, just displayed differently. The first Listview shows them as a TDateTime number, presumably before putting in the database. The last Listview shows them as a parsed string, presumably because that is how it is returned from the database. Contrary to what you said earlier "Also Filippos ListView is able to cast a TDateTime Value as a formated String" I don't think this is true. I don't think Listview converts anything, I think it just displays what it is given.
 

berndgoedecke

Active Member
Licensed User
Longtime User
Ok it was my mistake, right is DateTime-value(Versanddatum), but the first Listview(second jpg) has the same source-table as the SQLite Expert table(third jpg), where the date values seems to be zero(but they aren't, because this is the hex code of the value: 0000 2C84 5D40 CB42 (this is not the hex of a formated String)).
Also the Tables in jpg No.4 and No.5 has the same source-table
Some rare informations about the new ListView value-casting can be found here,(http://www.b4x.com/forum/german-forum/352-listview-dll-5.html#post13265) but only in german and in the SourceCode of fgexplorer http://www.b4x.com/forum/share-your-creations/2511-fgexplorer.html#post13867
There is a new object named Column Type
Coltype.New1
so the AddColumn parameters has changed:
Case "Datetime"
lv.AddColumn(SpNam(i),-1, 0, true, Coltype.cDateTime)
Coltype. shows the avaliable Column Typs.
I think Filippos DLL is right because the values, saved by SQLite-Expert are shown in the right way.

best regards

berndgoedecke
 

agraham

Expert
Licensed User
Longtime User
I'm afraid that I am totally confused as to what your problem is :confused: The Lieferdatum values which are TDateTimes seem to carry through consistently. The Versanddattum values, which are also TDateTimes show zero in the third jpg. What is the difference between the two columns?
 

berndgoedecke

Active Member
Licensed User
Longtime User
Now I understand where your confusion comes from.
Lieferdatum is column-type= Date (where no fraction part of double is needed)
Versanddatum is column-type = Datetime or timestamp ( where fraction part is essentaly needed to show the time-part of timestamp or date time).

best regards

berndgoedecke
 
Top