B4J Question Help for DatePicker!

universengo

Member
Hello all Pro!
I have an app that uses B4J with a DatePicker. I use DatePicker.Format = "dd/MM/yyyy" and that show is OK for my country.
But I don't know how to save this value to SQLite Database so that It can show later when I load this value back to DatePicker.
Help me! Thanks!
 

Xandoca

Active Member
Licensed User
Longtime User
You can store the DatePicker.Dateticks and use DateTime.Date(DatePicker1.DateTicks) to show the value as "dd/MM/yyyy".
Or you can store as "dd/MM/yyyy" and convert to ticks before using it in DatePicker1 (DateTime.DateParse("dd/MM/yyyy"))
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    
    Private DatePicker1 As DatePicker
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    DateTime.DateFormat = "dd/MM/yyyy"
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    xui.MsgboxAsync(DateTime.Date(DatePicker1.DateTicks), "B4X")
    DatePicker1.DateTicks = DateTime.DateParse("23/06/2023")
    xui.MsgboxAsync(DateTime.Date(DatePicker1.DateTicks), "B4X")
End Sub
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
If you will run queries against the date in the database, then you can maintain that format.
When you retrieve the date from the database, convert it to long and then set the dateticks to the long value
B4X:
    Dim datefromDB As Long = DateTime.DateParse("Value from DB")
    DatePicker1.DateTicks = datefromDB
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…