gpbimal Member Sep 26, 2022 #1 Hi! I'm new for b4a, i'm trying to get date and time in a string but unable. here is my code Dim DTStr As String DateTime.DateFormat="mm-dd" DTStr = DateTime.Date(DateTime.Now) DateTime.TimeFormat="hh:mm:ss a" DTStr = DTStr & " [" & DateTime.Time(DateTime.Now) & "]" Please correct me
Hi! I'm new for b4a, i'm trying to get date and time in a string but unable. here is my code Dim DTStr As String DateTime.DateFormat="mm-dd" DTStr = DateTime.Date(DateTime.Now) DateTime.TimeFormat="hh:mm:ss a" DTStr = DTStr & " [" & DateTime.Time(DateTime.Now) & "]" Please correct me
M Mahares Expert Licensed User Longtime User Sep 26, 2022 #2 gpbimal said: Please correct me Click to expand... First of all, what does the string you want to achieve look like. Give an example. There are mistakes in your code. For example the date format you have is for minutes and day not month and day. Please use code tags when posting code Upvote 0
gpbimal said: Please correct me Click to expand... First of all, what does the string you want to achieve look like. Give an example. There are mistakes in your code. For example the date format you have is for minutes and day not month and day. Please use code tags when posting code
William Lancee Well-Known Member Licensed User Longtime User Sep 26, 2022 #3 There's really only one error. To see date/time formats, hover over .DateFormat and click on 'formats'. B4X: DateTime.DateFormat="MM-dd" Upvote 0
There's really only one error. To see date/time formats, hover over .DateFormat and click on 'formats'. B4X: DateTime.DateFormat="MM-dd"
gpbimal Member Sep 27, 2022 #4 Thank you William, problem is solved. B4X: Dim DTStr As String DateTime.DateFormat="yyyy-MM-dd" DTStr = DateTime.Date(DateTime.Now) DateTime.TimeFormat="hh:mm:ss a" DTStr = DTStr & " [" & DateTime.Time(DateTime.Now) & "]" Log(DTStr) Now the result is: 2022-09-27 [03:19:49 PM] Upvote 0
Thank you William, problem is solved. B4X: Dim DTStr As String DateTime.DateFormat="yyyy-MM-dd" DTStr = DateTime.Date(DateTime.Now) DateTime.TimeFormat="hh:mm:ss a" DTStr = DTStr & " [" & DateTime.Time(DateTime.Now) & "]" Log(DTStr) Now the result is: 2022-09-27 [03:19:49 PM]
M Mahares Expert Licensed User Longtime User Sep 27, 2022 #5 gpbimal said: Now the result is: 2022-09-27 [03:19:49 PM] Click to expand... Since now you are posting how you want your string to look like, you can simplify your code like this: B4X: DateTime.DateFormat="yyyy-MM-dd [h:mm:ss a]" Dim DTStr As String = DateTime.Date(DateTime.Now) Log(DTStr) '2022-09-27 [10:59:36 AM] Upvote 0
gpbimal said: Now the result is: 2022-09-27 [03:19:49 PM] Click to expand... Since now you are posting how you want your string to look like, you can simplify your code like this: B4X: DateTime.DateFormat="yyyy-MM-dd [h:mm:ss a]" Dim DTStr As String = DateTime.Date(DateTime.Now) Log(DTStr) '2022-09-27 [10:59:36 AM]
gpbimal Member Sep 27, 2022 #6 Mahares said: Since now you are posting how you want your string to look like, you can simplify your code like this: B4X: DateTime.DateFormat="yyyy-MM-dd [h:mm:ss a]" Dim DTStr As String = DateTime.Date(DateTime.Now) Log(DTStr) '2022-09-27 [10:59:36 AM] Click to expand... Wow...Superb! Thank you Mahares, I was stupid that I unable to share my requirement (exactly what I need) Upvote 0
Mahares said: Since now you are posting how you want your string to look like, you can simplify your code like this: B4X: DateTime.DateFormat="yyyy-MM-dd [h:mm:ss a]" Dim DTStr As String = DateTime.Date(DateTime.Now) Log(DTStr) '2022-09-27 [10:59:36 AM] Click to expand... Wow...Superb! Thank you Mahares, I was stupid that I unable to share my requirement (exactly what I need)