Android Tutorial [B4X] DateUtils - Simplifies Date and Time Calcuations

Croïd

Active Member
Licensed User
Longtime User
sorry, but I'm stuck at this level!

addtime = DateUtils.AddPeriod(now, diff)
 

Attachments

  • add.zip
    7.3 KB · Views: 465

Croïd

Active Member
Licensed User
Longtime User
Don't confuse a period (diff) with a time value. They are not the same thing.

You cannot add two time values. The result will be meaningless.

You can add two periods to a time value.

Ah ! Ok thanks
 

chrjak

Active Member
Licensed User
Longtime User
Ho guys!

Is it possible to count down with some days left out? for example friday is left out. Then the time should be the same over the whole day.

E.g. Thursday 00:01 am : 2 Days and 23 hours ...
Friday 12:00 am : 2 Days and 0 minutes
Friday 04:00 pm: 2 Days and 0 minutes
Saturday 00:01 am: 1 Day and 23 hours...
And so on...


Is this possible with 2 days, too? e.g. Saturday and Sunday


Best regards!
Chris
 

chrjak

Active Member
Licensed User
Longtime User
In my example the current date is the day in front: (Friday 12:00 am : 2 Days and 0 minutes)
the target date is monday. And then it should calculate the days by leaving some days out (for example friday) then the calculated time should be like 2 days and 0 minutes when the day is a friday and the time is 12am

Best Regards
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not automatically. You will need to do some calculations for this.

The "brute force" solution is to calculate the period until Friday and then calculate the period between Saturday and the target date. You should do it in a loop which adds the periods until the period between Saturday and the target date is shorter than 5 days.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

I do not seem to find an answer for this and it is a little baffling. I understand that DateUtils is part of the IDE (core?) since 2.7.

I am using B4A Help 2.40 by A Graham to view the DateUtils.xml. The xml that I have for DateUtils is v 1.05

My B4A version is 4.30.

B4X:
DateUtils.xml - version 1.05

Nevertheless, only Period Methods and Fields are shown in B4A Help. No DateUtils methods show in the B4A Help, like DateUtils.GetMonthsNames.

Is it an XML issue or a B4A Help issue, or am I missing something?

Thank you for any help.

Sandy

PS: I opened the DateUtils.xml in Word and the methods are there.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Erel.

Maybe Andy Graham would update (WISH). I find the B4A help a valuable tool.

Best regards.

Sandy
 

LucaMs

Expert
Licensed User
Longtime User


Have you tried B4X object browser developed by Vader?
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Luca.

I have. It is extremely complete, and it works for DateUtils. I still gravitate to Andy's B4A Help better - maybe because I am used to it.

Ciao.

Sandy
 

Anser

Well-Known Member
Licensed User
Longtime User
Friends,

Is there a Function that returns the BoM() and EoM() ie Beginning of Month and End of Month() of a given date

To be more precise, if I provide a date as a parameter to this function it would return the Beginning date or End date of the month
For eg. BoM('20-Feb-2015') --> 01-Feb-2015
EoM('20-Feb-2015') --> 28-Feb-2015


Regards
Anser
 

LucaMs

Expert
Licensed User
Longtime User


B4X:
DateTime.DateFormat = "dd-MMM-y"

Dim MyDate As String = "20-Feb-2015"
Dim lngMyDate As Long = DateTime.DateParse(MyDate)

Dim Month As Int = DateTime.GetMonth(lngMyDate)
Dim Year As Int  = DateTime.GetYear(lngMyDate)
Dim DaysInMonth As Int = DateUtils.NumberOfDaysInMonth(Month, Year)
Dim BoM As String = DateTime.Date(DateUtils.SetDate(Year, Month, 1))
Dim EoM As String = DateTime.Date(DateUtils.SetDate(Year, Month, DaysInMonth))

Log(MyDate)
Log(BoM)
Log(EoM)
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…