Android Question Date.Format and DateTime.Add question

CidTek

Active Member
Licensed User
Longtime User
Using DateTime.DateFormat = "yyyyMMdd" I need to get todays date and yesterdays date.
log (DateTime.DateFormat = "yyyyMMdd")
Gives me 20130827 which is correct.

However while using the same dateFormat...
Tmpdate = DateTime.Add(DateTime.Now, 0, 0, -1)
Log(tmpdate)
gives me 1377498127481 but I expected 20130826

I would like to keep this simple with a few lines of code and not add any libraries such as DateUtils.
 

mangojack

Expert
Licensed User
Longtime User
Your Log output was Yesterdays date in "Ticks" ....

B4X:
 Dim Today, Yesterday As String
Dim TmpDate As Long

DateTime.DateFormat = "yyyyMMdd"
TmpDate = DateTime.Add(DateTime.Now, 0, 0, -1)
Today = DateTime.Date(DateTime.Now)
Yesterday = DateTime.Date(TmpDate)

Log (Today)
Log  (Yesterday)

Also see here ...
Get Yesterdays Date

Cheers mj
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…