B4J Question How to add 7 days to a Date Time Stamp

Peter Lewis

Well-Known Member
Licensed User
Longtime User
Hi All
I have looked at the jDateUtils and cannot find any process to seperate the month, day, year ect from a DateTime stamp that is stored in my sqlite database.

The string is 2017-04-01 02:37:56.0 and I want to add 7 days onto it and display the result.

Seems like it should be easy , I have tried all the subs and nothing gives me the answer. The closeest answer is on thread

https://www.b4x.com/android/forum/threads/datetime-increment-problem.78080/#post-494792

Thank you
 

EnriqueGonzalez

Expert
Licensed User
Longtime User
With datetime dateformat you can change how java reads the date and time strings, pair it with the sqlite datetime stamp.

Then use daytime date parse to get days and from there you can use dateutils.
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Try this

B4X:
    Dim daysDiff as int =  + or - the number of days ( -7 or 7)
    '
    Dim p As Period
    p.Days = daysDiff
    Dim newdate As Long = DateUtils.AddPeriod(DateTime.Now, p)
    '
 
Upvote 0

Peter Lewis

Well-Known Member
Licensed User
Longtime User
Try this

B4X:
    Dim daysDiff as int =  + or - the number of days ( -7 or 7)
    '
    Dim p As Period
    p.Days = daysDiff
    Dim newdate As Long = DateUtils.AddPeriod(DateTime.Now, p)
    '
Thank you, I eventually did this

B4X:
    DateTime.DateFormat   ="yyyy-MM-dd H:m:s.S"  'initial string 2017-05-03 14:49:17.0

    Dim datetick As Long = DateTime.DateParse(rowa(4))
    datetick= datetick + ((86400000)*7)
    lbldatedue.Text=(DateTime.Date(datetick))
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Like Erel says, not all days are created equal or so I fond out the hard way.

Day light saving days have 25 hours when you start day light saving and 23 hours when you finish.
Best use the p.days period.
 
Upvote 0
Top