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

Croïd

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

addtime = DateUtils.AddPeriod(now, diff)
 

Attachments

Croïd

Active Member
Licensed 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
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
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
 

tdocs2

Well-Known Member
Licensed 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
Thank you, Erel.

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

Best regards.

Sandy
 

LucaMs

Expert
Licensed 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.

Have you tried B4X object browser developed by Vader?
 

tdocs2

Well-Known Member
Licensed 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
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
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

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:
Top