nibbo Active Member Licensed User Longtime User May 30, 2014 #1 I want to make a string = to the current date and time in the format yyyy-MM-dd HH:mm:ss Simple enough in VB but not quite so in B4A. I can do the code below... Code: Copy Dim sNow As String = DateTime.getyear(DateTime.Now) & "-" & DateTime.GetMonth(DateTime.Now) & "-" & DateTime.GetDayOfMonth(DateTime.Now) & " " & DateTime.GetHour(DateTime.Now) & ":" & DateTime.getminute(DateTime.Now) & ":" & DateTime.GetSecond But that seems a little long winded. I am guessing I use DateTime.DateFormat but I can't seem to get it to work. Thanks in advance
I want to make a string = to the current date and time in the format yyyy-MM-dd HH:mm:ss Simple enough in VB but not quite so in B4A. I can do the code below... Code: Copy Dim sNow As String = DateTime.getyear(DateTime.Now) & "-" & DateTime.GetMonth(DateTime.Now) & "-" & DateTime.GetDayOfMonth(DateTime.Now) & " " & DateTime.GetHour(DateTime.Now) & ":" & DateTime.getminute(DateTime.Now) & ":" & DateTime.GetSecond But that seems a little long winded. I am guessing I use DateTime.DateFormat but I can't seem to get it to work. Thanks in advance
DonManfred Expert Licensed User Longtime User May 30, 2014 #2 Look at documentation (or for examples) of using DateTime.DateFormat and DateTime.Timeformat Upvote 0
nibbo Active Member Licensed User Longtime User May 30, 2014 #3 Err... I did and could not find an example that worked, that's why I am asking! Upvote 0
M Mahares Expert Licensed User Longtime User May 30, 2014 #4 If you looked at the documentation and still need help, here is your solution: Code: Copy Dim OrigFormat As String=DateTime.DateFormat 'save orig date format DateTime.DateFormat="yyyy-MM-dd HH:mm:ss" Dim MyDate As String=DateTime.Date(DateTime.Now) Msgbox(MyDate,"") DateTime.DateFormat=OrigFormat 'return to orig date format Upvote 0
If you looked at the documentation and still need help, here is your solution: Code: Copy Dim OrigFormat As String=DateTime.DateFormat 'save orig date format DateTime.DateFormat="yyyy-MM-dd HH:mm:ss" Dim MyDate As String=DateTime.Date(DateTime.Now) Msgbox(MyDate,"") DateTime.DateFormat=OrigFormat 'return to orig date format
nibbo Active Member Licensed User Longtime User May 30, 2014 #5 Thanks Mahares, I now understand how DateFormat works. Upvote 0