Locking the date


I want to lock the date for the promotion based from start and end date.
the list item in listbox is based from today’s date. If the date start is match then promotion start and stop when the end date is over.

this code seem to works, but not covering all. still has some items are passed.

dim dd as new date
if ListPromo.cell(gg,8)>=str(dd.SQLDate) or ListPromo.cell(gg,7)>=str(dd.SQLDate) then 'cell 8 = end date cell 7=start date

Select case ggg
case "D1"
case "D2"
case "D3"
case "D4"
End Select

any help?


Maybe here you need AND and <=

End date 2024-05-03
Start date 2023-12-01
Today date 2023-05-02

Your original code will stop at the Break.

Dim dd As New date
If "2024-05-03">=dd.SQLDate Or "2023-12-01">= dd.SQLDate Then
  //should not be in this range
End If

Changed to And and <= does not stop at the break

If "2024-05-03">=dd.SQLDate And "2023-12-01"<= dd.SQLDate Then
  //should not be in this range
End If

is this your problem?

Yes, This is actually what I need, I want to use between two dates from a listbox.

but still has a problem

if ListPromo.cell(gg,8)>=str(dd.SQLDate) and ListPromo.cell(gg,7)<=str(dd.SQLDate) then 'cell 8 = end date cell 7=start date

Start date = 2023-05-01 end date = 2023-05-08 does not cover. based from today 2023-05-03


I’m sorry but I don’t know what you mean with “does not cover”

This code works:

Dim dd As New date
If "2023-05-08">= dd.SQLDate And "2023-05-01"<= dd.SQLDate Then
  //we should get here
End If

Note: I don’t know why you use str(dd.SQLDate) as dd.SQLDate is already a string, but even with str(dd.SQLDate) the code works (at least on Mac)

Note2: Maybe ListPromo.cell(gg,8) is not “2023-05-08” and/or ListPromo.cell(gg,7) is not “2023-05-01” ?

Your are using an older version of Xojo with API1, so Listbox.Cell() returns Text. What you are doing in your code is comparing a text with a string. This can’t work as expected.

A better approach may be working with dates, in detail with totalseconds.

dim dd as New Date
dim dStart as New Date
dim dEnd as New Date

dStart.SQLDate = ListPromo.cell(gg,7) // content of cell 7 must be a date in SQL-Format
dEnd.SQLDate = ListPromo.cell(gg,8) // content of cell 8 must be a date in SQL-Format

if dd.Totalseconds >= dStart.Totalseconds And dd.TotalSeconds <= dEnd.TotalSeconds then

Hi, Thanks for the help, but still not covering. My Goals is like this pict,


Promo A,B,C are active, because the end date still going till 2023-05-10
and Promo D is not active, because promo just started by tomorrow (2023-05-04) based from todays’date.

something like that.


Everything you need to get your desired result is mentioned in my post. You only have to adopt it to your way of putting data into the listbox. The calculation has to be done for every row…

It would be helpful if you show your code, how you fill the listbox…

Like this?

2023-05-03_07-57-52.2023-05-03 08_02_21

This is the code in the button (converted TextField1.Text to date just to use date and not the TextField contents):

Dim dd As New date
dd.SQLDate = TextField1.Text

For i As Integer = 0 To 3
  If Listbox1.Cell(i, 2) <=dd.SQLDate And dd.SQLDate <= Listbox1.Cell(i, 3) Then
    Listbox1.Cell(i, 4) = "Active"
    Listbox1.Cell(i, 4) = "Not Active"
  End If

Used Xojo 2018r3

I guess your problem is not with the If statement. Can you create a sample project and illustrate the wanted result? someone can review your code that way.

Note: I changed the If order because that way is more clear for me to:
Date Start <= Date to check <= Date End

This is the code in the button (converted TextField1.Text to date just to use date and not the TextField contents):

I am forgot to check the datatype, yes it was text, changing the datatype into date solved the problem.
I am using Sqlite data browser for linux and there is no Date Datatypeoption. So I edited the database on windows and work.


thanks for all the help.