Q: Datetime in human readable form

chuckyegg

Member
Licensed User
Longtime User
Hi guys

This feels like it should be really simple, but I can't get dates stored in TEXT fields in SQL into human readable form.

What I get is strings like "1350570465000"
What I want is "31/10/2012 13:59:01"

My SQL insert looks like this:
B4X:
SQL1.ExecNonQuery("INSERT INTO Table VALUES('Name', '" & DateTime.DateParse(DateTime.Date(DateTime.Now)) & "'")

I have searched and looked at the guide, but I think it's too basic to have troubled most people!


TIA
 

Mahares

Expert
Licensed User
Longtime User
You cannot use the DateTime inside a SQL statement:
B4X:
Dim MyDT, MyName as string
MyDT= DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now)
MyName="chuckyegg"
SQL1.ExecNonQuery2("INSERT INTO Table VALUES(?,? )" , Array as string (MyName,MyDT))
 
Last edited:
Upvote 0

chuckyegg

Member
Licensed User
Longtime User
Thanks, but I still get the long digits

This is my current code:

B4X:
   DateTime.DateFormat = "dd/MM/yyyy HH:mm:ss"
   Dim strDateTime As String
   strDateTime = DateTime.DateParse(DateTime.Date(DateTime.Now))
   Log(strDateTime)

   datHubber.ExecNonQuery2("INSERT INTO MessageLog VALUES(?,?,?,?,?,?)" , Array As String (intMessageID, MobileNumber, strDateTime, Message, Direction, Status))

The Log() shows the numeric "date", the same as gets recorded in the table.

This is the code that creates the table:

B4X:
   If datHubber.ExecQuerySingleResult("SELECT count(name) FROM sqlite_master WHERE type='table' AND name ='MessageLog'") = 0 Then
      datHubber.ExecNonQuery("CREATE TABLE MessageLog (MessageID INTEGER, MobileNumber TEXT, DateCreated TEXT, Message TEXT, Direction TEXT, Status TEXT)")
   End If

Any other ideas?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
B4X:
DateTime.DateParse(DateTime.Date(DateTime.Now))
Should be:
B4X:
DateTime.Date(DateTime.Now)

If you want to show both date and time, you can do this:
B4X:
strDateTime=DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now)
 
Last edited:
Upvote 0
Top