Android Question noob: cannot get datetime into string??

Sebastian Heyn

Member
Licensed User
Longtime User
Hi,

this doesnt seem to work

Dim now As Long
Dim df As String
Dim date_string As String
DateTime.DateFormat = "yyyyMMdd"
DateTime.TimeFormat = "HHmmss"
date_string=DateTime.Date(now) & "_" & DateTime.Time(now)
Msgbox("The date is: " & date_string, "")

if I do msgbox(datetime.date(now),"") etc it works. Where am I going wrong here?
 

DonManfred

Expert
Licensed User
Longtime User
I cannot see any errormessage. Maybe you missed it to post here?
Maybe you did not explain what you expect and what you get.

B4X:
Dim df As String
Dim date_string As String
DateTime.DateFormat = "yyyyMMdd"
DateTime.TimeFormat = "HHmmss"
date_string=DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.Now)
Msgbox("The date is: " & date_string, "")
 
Last edited:
Upvote 0

Sebastian Heyn

Member
Licensed User
Longtime User
Soorry.

My mistake. when changing from the example code which was

Msgbox("The date is: " & DateTime.Date(now) & CRLF & _"The time is: " & DateTime.Time(now), "")

to using a string variable, I accidentally deleted the line now = DateTime.Now

Then, the date was displayed: 19691231_190000

I am not really familiar with the syntax yet. and iam not happy with the documentation ( too view examples -compared to bascom- :)) so I get annoyed and ask many questions. :))
 
Upvote 0

eps

Expert
Licensed User
Longtime User
You can probably do this is one go.

As in :

DateTime.Dateformat = "MM/dd/yyyy HH:mm:ss"

and I think you can only really set this once. Maybe that is the issue you are getting.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What are you trying to end up with, I'm still not sure...?
Is it?
DDMMCCYY_HHMMSS?

Not really... Problem was that the DIMmed a long named now and wanted to use it in
B4X:
date_string=DateTime.Date(now) & "_" & DateTime.Time(now)
and wondered why he get 19691231_190000 and not "today"...

DIM now as long will not really work if you dont give a correct value to now.... :)
 
  • Like
Reactions: eps
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and I think you can only really set this once
That´s wrong. You can use it as often you want. But be aware. the last one is active till you set a new Date- and/or Time-Format

B4X:
	Dim date_string As String
	DateTime.DateFormat = "yyyyMMdd"
	DateTime.TimeFormat = "HHmmss"
	date_string=DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.Now)
	Log(date_string) ' -> 20140430_222235
	DateTime.DateFormat = "yyMMdd"
	DateTime.TimeFormat = "HHmm"
	date_string=DateTime.Date(DateTime.Now) & "_" & DateTime.Time(DateTime.Now)
	Log(date_string) ' -> 140430_2222
 
  • Like
Reactions: eps
Upvote 0

Sebastian Heyn

Member
Licensed User
Longtime User
Exactly. If you dont give it a value its probably 0 or something
Which really made me wonder, as I thought unix time is 1.1.1970, 0:0:0 -> But thats probably because the timezone is not right on my AVD.

If anyone wonders, what iam trying to end up with: The timecode is used to name files. Like that the files are in an alphabetical (numeric) order.
I personally dont like special characters in files, : is possible i think but / should not work with filenames....
 

Attachments

  • mistake.png
    mistake.png
    26.8 KB · Views: 208
Upvote 0
Top