Silly question.
Probably really simple but I can’t find the answer
I wish to compare two dates. Here is the code
var d1, d2 as Double
d2 = DateTimePicker1.SelectedDate.SecondsFrom1970 //when do I want the alarm to fire?
d1 = ToDoWindow.TaskListBox.CellTextAt(ToDoWindow.TaskListBox.SelectedRowIndex,2).ToDouble // what is the current time?
// for testing only
System.DebugLog "Selected date and time for alarm " + d2.ToString
System.DebugLog "Current date and time : " + d1.ToString
//the Floor gives the integer value of, in this case, a double
// compare the dates
if Floor(d1) >= Floor(d2) then
MessageBox “Alarm”
else
end if
No matter what I try the line
ToDoWindow.TaskListBox.CellTextAt(ToDoWindow.TaskListBox.SelectedRowIndex,2).ToDouble // what is the current time?
I only get the first digits of the date (i.e. if it is 2025-06-01) I only get 2025
Any ideas?
Regards
Hi Michael,
It seems to me that you want to create an alarm on or one day after the date in the listbox which is shown in SQLDate format?
If that is the case, then you should be using datetime objects not doubles.
d1 = DateTIme.FromString(ToDoWindow.TaskListBox.CellTextAt(ToDoWindow.TaskListBox.SelectedRowIndex,2))
Now you can compare d1.sqldate >= d2.sqldate
HTH
Wayne
The String.ToDouble
method stops when it reaches a non-numeric character, such as “-”.
Instead of parsing the cell text, store the date object alongside the text by using the cell’s “tag”.
For example:
Dim time As DateTime = DateTime.Now
TaskListBox.AddRow(time.SQLDateTime)
TaskListBox.CellTagAt(TaskListBox.LastAddedRowIndex, 0) = time
Then:
d1 = ToDoWindow.TaskListBox.CellTagAt(ToDoWindow.TaskListBox.SelectedRowIndex,2).SecondsFrom1970 // what is the current time?
2 Likes
At ListBox populated time, add the ateTime to CellTag, so you will have a value for computing (the Tag) and the user displayed object.
If you do that correctly (wit a Locale) you will be able (elsewhere) to display the full date (Saturday dd month YYYY)
More info: search in this forum (an entry with a xojo sample) and in the Language Reference: DateTime.
Sometimes with XojoBASIC language *, you have to do two times the job to be at ease later:
Once for the developer: to be able to deal with dates,
once for the user: diplay the information in a user firendly format.
- It ws easier with the REALbasic Language.
IMHO
|
• |
DateTime objects can be directly compared using <, >, <=, >=, =, and <>. |
|
• |
These comparisons are based on the actual moment in time (down to the microsecond). |
|
• |
You can also subtract one from another to get a DateInterval. |
Var d1 As DateTime = DateTime.Now
Var d2 As DateTime = d1.AddInterval(0, 0, 1) ’ Adds 1 day
If d2 > d1 Then
MessageBox(“d2 is after d1”)
Else
MessageBox(“d2 is not after d1”)
End If
Thank you Wayne.
I think that is what I was trying to do.
The last time I used this it was between to DatePickers.
Will test and advise
Regards
Thank you for resolving my mystery of why only 2025 showed.
Makes sense now.
Regards