Normal Topic if then statement with a date field (Read 699 times)
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
if then statement with a date field
Feb 4th, 2004 at 3:20pm
Print Post Print Post  
I am trying to use an if then statement with a date field element. I have a field element named carsolddate it is set as a date field.

I want different things to happen based on the date. example is
If carsolddate date is before 01/01/2004  do this if it is after 12/31/2003 do that.


     
I have tried simple thing like

iF      carsolddate < 01/01/2004
{
     Writeln("before")
     
}
else
{
     Writeln("after")
}

I have tried date as 2004/1/1
I have tried creating a var as date and using @todate()
Obviously sesame can do this, I just need some direction.

Help please.
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: if then statement with a date field
Reply #1 - Feb 4th, 2004 at 3:41pm
Print Post Print Post  
Bill, try this, place it in element exit event of carsolddate. Make sure that CarSoldDate is the element name and just label. Also make sure that it is date field. If you place field using : at the end, default LE format is text.

var vMessage as String

if  carsolddate < "01/01/2004" then
{
    vMessage = "Before"
     Writeln( vMessage)
 
}
else if carsolddate >= "1/1/2004" then      
//othewise empty LE will display "after"
{
     vMessage = "After"
      Writeln(vMessage)
}

« Last Edit: Feb 4th, 2004 at 5:59pm by Bharat_Naik »  
Back to top
 
IP Logged
 
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
Re: if then statement with a date field
Reply #2 - Feb 4th, 2004 at 5:26pm
Print Post Print Post  
Thanks for the effort
but I get the same results always comes up after
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: if then statement with a date field
Reply #3 - Feb 4th, 2004 at 5:47pm
Print Post Print Post  
Wrap the date you are using for the comparison in the @d() function to turn it into a date.

iF carsolddate < @d("01/01/2004")
{
Writeln("before")
   
}
else
{
Writeln("after")
}

Or, alternately, you can put it in double quote and use the systme date order YYYY/MM/DD:

iF carsolddate < "2004/01/01"
{
Writeln("before")
   
}
else
{
Writeln("after")
}
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: if then statement with a date field
Reply #4 - Feb 4th, 2004 at 6:02pm
Print Post Print Post  
Mark, in Q&A we never had to put date under quotes. Why is it different in Sesame?

It works in Sesame if we put quotes around the dates in if statement.

In Q&A no quotes were expected.
  
Back to top
 
IP Logged