GetDayOfMonth

sigster

Active Member
Licensed User
Longtime User
Hi , who can tell me where I can find sample on the forum Please

Do you have sample how I can use GetDayOfMonth

neet help on GetDayOfMonth the rest I figure out :)
need to get the date number and then gone use it SQL
so I can get all record on Sample "Monday"

Regards
Sgster
 

klaus

Expert
Licensed User
Longtime User
I don't really undestand what your problem is.

With DateTime.Get DayOfTheMonth(Ticks As Long) you get the day of the month. The argument must be ticks.

But if you want to filter on Monday I think you should look for DateTime.GetDayOfWeek(Ticks As Long). The result is a number (1 = sunday). You could use an array for the day names.

Best regards.
 
Upvote 0

sigster

Active Member
Licensed User
Longtime User
Thanks

This works well

B4X:
   If DateTime.GetDayOfWeek(DateTime.Now) = 1 Then
      Lab_lat.text= "Sunday"
   Else
   If DateTime.GetDayOfWeek(DateTime.Now) = 2 Then
      Lab_lat.text= "Monday"
   Else
   If DateTime.GetDayOfWeek(DateTime.Now) = 3 Then
      Lab_lat.text= "Tuesday"
   Else
   If DateTime.GetDayOfWeek(DateTime.Now) = 4 Then
      Lab_lat.text= "Wednesday"
   Else
   If DateTime.GetDayOfWeek(DateTime.Now) = 5 Then
      Lab_lat.text= "Thursday"
   Else
   If DateTime.GetDayOfWeek(DateTime.Now) = 6 Then
      Lab_lat.text= "Friday"
   Else
   If DateTime.GetDayOfWeek(DateTime.Now) = 7 Then
      Lab_lat.text= "Saturday"
   Else

   End If
   End If
  End If
 End If
 End If
 End If
 End If
 
Upvote 0

joseluis

Active Member
Licensed User
Longtime User
and how about this?

B4X:
Dim WeekDaysStr() As String
WeekDaysStr = Array as String ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
Lab_lat.text= WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) + 1)
 
Upvote 0

volvomann

Active Member
Licensed User
Longtime User
Eroor mesage

Hello!
When I use the code that's over here I get this error message:

LastException java.lang.ArrayIndexOutOfBoundsException

What can be wrong?

Regards,
volvomann
 
Upvote 0

volvomann

Active Member
Licensed User
Longtime User
Code

Sorry i forgot

Sub Button1_Click
Dim WeekDaysStr() As String
WeekDaysStr = Array As String ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
Label4.Text=WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) + 1)
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This line
B4X:
Label4.Text=WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) + 1)
must be
B4X:
Label4.Text=WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) - 1)
The day indexes go from 1 to 7.
Your array indexes must be from 0 to 6.

Best regards.

EDIT: removed the blank characters reported in post #11.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Klaus: I think he may still get an error because datetime should be one word.
Label4.Text=WeekDaysStr(DateTime.GetDayOfWeek(Date Time.Now) - 1)

should be:
Label4.Text=WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) - 1)
 
Upvote 0

Peter Faase

Member
Licensed User
Longtime User
Hi Girls and Boys,

and how about this?

B4X:
Dim WeekDaysStr() As String
WeekDaysStr = Array as String ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
Lab_lat.text= WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) + 1)

I did put this lines into a sub with a parser in this way

DagNaam=WeekDaysStr(DateTime.GetDayOfWeek(DateTime.DateParse(Maand & "/" & Dag & "/" & Jaar) -1))

all things work fine except when it comes to a sunday (04-21-1907)
then i get an: java.lang.ArrayIndexOutOfBoundsException: length=7; index=7

is an array not allowed to get a 0?

Thanks in advance for helping me out here!

Cheers,

Peter
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
You copied the wrong code, this is correct :
B4X:
Lab_lat.text= WeekDaysStr(DateTime.GetDayOfWeek(DateTime.Now) - 1)
The GetDayOfWeek function returns a number between 1 and 7.
But the array begins with index 0 so the last index is 6 and you get the error when GetDayOfWeek = 7.
So you must substract 1 and not add one.

Best regards.
 
Upvote 0

Peter Faase

Member
Licensed User
Longtime User
Thanks for answering Klaus, i just found that out and changed my post :)

So my only 'problem' that it goes wrong when the date is a a sunday.
 
Last edited:
Upvote 0

Peter Faase

Member
Licensed User
Longtime User
Okay for some reason, i don't understand at this very moment i got it working in this way:

B4X:
WeekDaysStr = Array As String ("zondag","maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag")
TempStr = DateTime.GetDayOfWeek(DateTime.DateParse(Month & "/" & Day & "/" & Year ) -1)
If TempStr = 7 Then TempStr = 0
DagNaam=WeekDaysStr(TempStr)

One reason could be that i get the value of my date out of a mysql database?

Cheers,

Peter
 
Upvote 0
Top