Unparseable date

gapi

Active Member
Licensed User
Longtime User
How parse data for insert it on sqlite db ?

B4X:
Dim d As Long

DateTime.DateFormat = "yyyy-MM-dd"
d = DateTime.DateParse(txtData.Text)

Dim m As Map
    m.Initialize
    m.Put("data", DateTime.Date(d))
    m.Put("destinaz", destinaz)
    ListOfMaps.Add(m)

DBUtils.InsertMaps(Main.SQL_myDb, "orders", ListOfMaps)

in activity_create ...
B4X:
If FirstTime = True Then
      ' initialize date to current date at start of the program
       DataOdierna = DateTime.Now
       DateTime.DateFormat = "dd/MM/yyyy"
       txtData.Text= DateTime.Date(DataOdierna)
End If

return me >> java.text.ParseException: Unparseable date: "06/09/2012" :BangHead:
 

mc73

Well-Known Member
Licensed User
Longtime User
In your activity_create you have "dd/MM/yyyy", while in your insertion routine, you have "yyyy-MM-dd". I think parsing would work ok, if you had written "dd/MM/yyyy" also in this routine. Then, if you need your date stored in "yyyy-MM-dd" format, you can set it just after parsing.
 
Upvote 0

gapi

Active Member
Licensed User
Longtime User
I would like show the date in the format dd/mm/yyyy user but invisibly insert in the format yyyy-mm-dd in the database. How can do it ?
tnx ;)
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I think that simply altering a bit your insertion code, will do it:
B4X:
'yourInsertMapsSub
        Dim d As Long
        DateTime.DateFormat = "dd/MM/yyyy"
        d = DateTime.DateParse(txtData.Text)
        DateTime.DateFormat = "yyyy-MM-dd"
        Dim m As Map
        m.Initialize
        m.Put("data", DateTime.Date(d))
        m.Put("destinaz", destinaz)
        ListOfMaps.Add(m)
        DBUtils.InsertMaps(Main.SQL_myDb, "orders", ListOfMaps)
 
Upvote 0
Top