String to date!?

[code] Dim theDate as New Date
Dim converted as Boolean
converted = ParseDate( arrVar(7), theDate)
IF converted THEN
System.DebugLog CurrentMethodName + " :: " + theDate.AbbreviatedDate
'JOLT.dteSubscriptionEnd = theDate.AbbreviatedDate
JOLT.dteSubscriptionEnd = theDate.SQLDateTime

  End If[/code]

In Classic ASP, it will be like:

 JOLT.dteSubscriptionEnd = CDate( arrVar(7) )

Excuse me. I’m tired…

JOLT.dteSubscriptionEnd = theDate

DIM dteToday as New Date

IF JOLT.dteSubscriptionEnd > dteToday.SQLDate THEN
MsgBox “hello world!!”
END IF[/code]

Does greater than… and less than… only work on Integers!?

DIM dteToday as New Date

IF JOLT.dteSubscriptionEnd.Operator_Compare(dteToday) > 0 THEN
MsgBox “hello world!!”
END IF[/code]

Somewhere, along the line, this could be sort of the answer…!
But something is missing.

Some background:

If you want to create a class that can be compared to something else, you implement the Operator_Compare method. This will let you do things like if myClass1 > myClass2 then …. You don’t have to call Operator_Compare directly.

Some of the native classes, like Date, already implement that, so this is perfectly valid:

if someDate > someOtherDate then …

In your original code, you tried to compare a date to a string (if JOLT.dte > dteToday.SQLDate), and that won’t work. Instead, you could simply do this:

if JOLT.dteSubscriptionEnd > dteToday then …

or this:

if JOLT.dteSubscriptionEnd.SQLDate > dteToday.SQLDate …

If you are only interested in the date, not the time, use the second version.

use Operator Compare or .TotalSeconds for greater/lesser comparison operations

You can compare dates directly. Date already has an OperatorCompare that compares TotalSeconds.

Except that TotalSeconds considers the time too.

Thank you for the input!
Thank you for the seconds, in this case the date, the day, will be good enough. But in other cases, seconds may be needed. It’s true!

The value is empty, to start with.
Why are there constant errors when trying alternatives such as NOT NIL and plenty alternatives!?

DIM dteToday as New Date

IF JOLT.dteSubscriptionEnd <> “” THEN
IF JOLT.dteSubscriptionEnd > dteToday THEN
MsgBox “hello world!!”
END IF[/code]

You can’t compare a class to a string. You can (and should) check to make sure it’s not nil.

if not( JOLT.dteSubscriptionEnd is nil ) and JOLT.dteSubscriptionEnd > dteToday then …

You can also do it this way, if you want to save some typing:

if JOLT.dteSubscriptionEnd IsA Date and JOLT.dteSubscriptionEnd > dteToday then …

Finally, you can do this, but I’ve started moving away from this form in my own code because of potential side-effects:

if JOLT.dteSubscriptionEnd <> nil and JOLT.dteSubscriptionEnd > dteToday then …

Thank you very much for the post!
That last line I also tried. How would you know!?

In general, my personal way of solving problems is sometimes simply to remove the problem, to look on another, maybe less fancy and attractive, but at least working solution.

JOLT.bolSubscriber was the case at this time:

' ## INSERT SUBSCRIBER DATE FOR USER DIM dteEnd as New Date DIM bolDte as boolean bolDte = ParseDate(arrVar(7), dteEnd) IF bolDte = TRUE THEN DIM d as New Date IF dteEnd >= d THEN JOLT.bolSubscriber = TRUE ELSE JOLT.bolSubscriber = FALSE END IF

I really miss dateAdd and dateDiff from Classic ASP…! :slight_smile:

<% IF JOLT.dteSubscriberEnd >= date() THEN btnSave.Enable = TRUE %>
This is only imaginary code, but in this case, the date, REALbasic really differ from Visual Basic. (VB Script that is.)
Oh well! It’s the way it is! :slight_smile: Just my thoughts! :slight_smile:

well that’s the difference between Visual Basic’s pseudo OOP and real OOP in xojo. You would run into same problem with other stricter languages too. Make yourself more familiar with data types and OOP.