Date for little calendar

Hello Group, I would like to make a small calendar, I need to know the first day of the month.

For example May 2022, first day is Sunday.

This may help:
https://documentation.xojo.com/api/data_types/datetime.html#datetime-dayofweek

The first thing you need to do is determine the method you will use to input the date you want to find the name of that day. Will that be something you code or will it be input by the user? If it is input by the user it may be important to have them input the date in a specific format or input the year, the month and the day separately so that you can build the correct format to convert to the DateTime object Alberto referenced in his link for the DateTime Help for DayOfWeek. Here is some sample code that would work if the date was input as a SQLdate string.

  Var SQLDate As String = "2022-05-01"
  Var dt As DateTime = DateTime.FromString(SQLDate)
  Var dow As Integer = dt.DayOfWeek
  Var dayname As String
  Select Case dow
  Case 1
    dayname = "Sunday"
  Case 2
    dayname = "Monday"
  Case 3
    dayname = "Tuesday"
  Case 4
    dayname = "Wednesday"
  Case 5
    dayname = "Thursday"
  Case 6
    dayname = "Friday"
  Case 7
    dayname = "Saturday"
  End Select
1 Like

see also
\Xojo2021r31\Example Projects\Desktop\Custom Controls
CalendarWindow.xojo_binary_project
it is not perfect but a template

Return any errors

Perfect, it’s OK !!! THANKS Mr.

I tend to prefer this method since it is able to handle other locales.

Public Function DayOfWeekString(extends d As DateTime) As String
  ' Returns the current locale-based day name from the supplied DateTime
  Dim currentLocale As Locale = Locale.Current
  
  Var dateString As String = d.ToString (currentLocale, DateTime.FormatStyles.Full, DateTime.FormatStyles.None)
  
  Var dayname As String = dateString.NthField (",", 1)
  Return dayname
  
End Function

I got it from another forum but I won’t name it. :wink:

2 Likes

Mr, your example work perfectly … but i have this format date. You example is for format date yyyy-mm-dd, i have ths format dd/mm/yyyy. How i can convert it ?

Try .FromString and use the correct locale that uses dd/mm/yyyy
https://documentation.xojo.com/api/data_types/datetime.html#datetime-fromstring

If you can’t make that work, you can use String.Right, String.Left and String.Middle to extract yyyy, dd, mm and convert to yyyy-mm-dd if needed.