Date calculations

hackhack

Active Member
Licensed User
Longtime User
Ok, I have DateTime.Now and SomeFutureDate - if I quickly wish to display the difference between now and future as days/hours/months/seconds - is there a quick way to do that I overlooked?

For a brief moment i thought perhaps i could subtract the future long with the current long and do datetime routines on them, but that ended up total nonsense :)
 

kanaida

Active Member
Licensed User
Longtime User
I know it's wierd dealing with ticks lol

I was trying to make a stopwatch and did this:

Start = DateTime.Now
End = DateTime.Now

TimeTaken = End - Start
???
Profit!

lol

I think you can try: TimeTaken / DateTime.TicksPerDay.
that should give you How many days difference I think.
More than that, there really should be a Date/DateTime Class that handles dates in english.
 
Last edited:
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Thanks, but I erased it when it didn't work.

However I may redo it later :)

However, you are saying that one can't use datetime functions to extract day/hour/minute after subtracting the time amount?
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Also, is it possible to generate a complete time point?

This

B4X:
DateTime.DateParse("07/07/2011 06:00:00")

Doesn't seem to work, the time is set to 00:00:00

B4X:
DateTime.DateParse("07/07/2011") + DateTime.TimeParse("06:00:00")

Doesn't work either, the time is 6, but its sometime decades in the future - not surprising since the docs say that timeparse adds "today" to the value returned .

Can one AND out the date value of the timeparse result and OR it with the dateparse result? Or is there another option?
 
Upvote 0

SteveBee

Member
Licensed User
Longtime User
You should ensure to set the *format* before you attempt to parse:
e.g.
B4X:
....
Dim DT As Long
DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ss"
DT = DateTime.DateParse(Attributes.GetValue(i))
DateTime.DateFormat = "dd-MMM-yyyy HH:mm"
lblSchedStart.Text = DateTime.Date(DT)
....
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
You should ensure to set the *format* before you attempt to parse:
e.g.
B4X:
....
Dim DT As Long
DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ss"
DT = DateTime.DateParse(Attributes.GetValue(i))
DateTime.DateFormat = "dd-MMM-yyyy HH:mm"
lblSchedStart.Text = DateTime.Date(DT)
....

Wait what, Attributes.GetValue? What's that returning I thought that was related to xml? Or is it just an example?

Also, dateformat can include the time? (Docs didn't say) - that may change things. :)
 
Upvote 0

SteveBee

Member
Licensed User
Longtime User
This was just copied/pasted from my code.
Attributes.GetValue(i) is just a value - yes I was parsing xml

If it makes it easier for you:
B4X:
DT = DateTime.DateParse(strDateTime)
where strDateTime is a string representation of a DT
 
Upvote 0
Top