choosing a date

This is a discussion on choosing a date within the MySQL Database forums, part of the Database Forums category; Hi there, I'm trying to create a sql statement in which a date is compared to another date and ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-03-2008
Sjef
 
Posts: n/a
Default choosing a date

Hi there,
I'm trying to create a sql statement in which a date is compared to another
date and depending on the comparison one is chosen.
such as:

if (date_add(cur_date(), interval 30 day) >=
'$thisDate','$this->date',date_add(cur_date(), interval 30 day)

So: if the current date plus 30 days is larger than thisDate then thisDate
is used, else the date plus 30 days is used.
But: it doesn't do what I expected it to do. Can anybody pint out the
reason. No error message or so ...

Thanks, Sjef


Reply With Quote
  #2 (permalink)  
Old 01-03-2008
Paul Lautman
 
Posts: n/a
Default Re: choosing a date

Sjef wrote:
> Hi there,
> I'm trying to create a sql statement in which a date is compared to
> another date and depending on the comparison one is chosen.
> such as:
>
> if (date_add(cur_date(), interval 30 day) >=
> '$thisDate','$this->date',date_add(cur_date(), interval 30 day)
>
> So: if the current date plus 30 days is larger than thisDate then
> thisDate is used, else the date plus 30 days is used.
> But: it doesn't do what I expected it to do.

So what DOES it do?

> Can anybody pint out the
> reason. No error message or so ...

I can't pint it out, but I might be able to point it out.

I have to say that I'm amazed that you didn't get an error as there is a
closing bracket missing.



Reply With Quote
  #3 (permalink)  
Old 01-03-2008
Sjef
 
Posts: n/a
Default Re: choosing a date

The result was the date plus 30 days

"Paul Lautman" <paul.lautman@btinternet.com> schreef in bericht
news:5u4rclF1gg49eU1@mid.individual.net...
> Sjef wrote:
>> Hi there,
>> I'm trying to create a sql statement in which a date is compared to
>> another date and depending on the comparison one is chosen.
>> such as:
>>
>> if (date_add(cur_date(), interval 30 day) >=
>> '$thisDate','$this->date',date_add(cur_date(), interval 30 day)
>>
>> So: if the current date plus 30 days is larger than thisDate then
>> thisDate is used, else the date plus 30 days is used.
>> But: it doesn't do what I expected it to do.

> So what DOES it do?
>
>> Can anybody pint out the
>> reason. No error message or so ...

> I can't pint it out, but I might be able to point it out.
>
> I have to say that I'm amazed that you didn't get an error as there is a
> closing bracket missing.
>
>
>



Reply With Quote
  #4 (permalink)  
Old 01-03-2008
Paul Lautman
 
Posts: n/a
Default Re: choosing a date

Sjef wrote:
> "Paul Lautman" <paul.lautman@btinternet.com> schreef in bericht
> news:5u4rclF1gg49eU1@mid.individual.net...
>> Sjef wrote:
>>> Hi there,
>>> I'm trying to create a sql statement in which a date is compared to
>>> another date and depending on the comparison one is chosen.
>>> such as:
>>>
>>> if (date_add(cur_date(), interval 30 day) >=
>>> '$thisDate','$this->date',date_add(cur_date(), interval 30 day)
>>>
>>> So: if the current date plus 30 days is larger than thisDate then
>>> thisDate is used, else the date plus 30 days is used.
>>> But: it doesn't do what I expected it to do.

>> So what DOES it do?
>>
>>> Can anybody pint out the
>>> reason. No error message or so ...

>> I can't pint it out, but I might be able to point it out.
>>
>> I have to say that I'm amazed that you didn't get an error as there
>> is a closing bracket missing.

> The result was the date plus 30 days


Please do not top post (top posting fixed).

That is strange, I would have expected an error as there is a bracket
missing.

Can you echo the query as it would have been executed, so we can see what
'$thisDate' resolves to.

We can also understand how an if statement with an obvious syntax error
manages to run!



Reply With Quote
  #5 (permalink)  
Old 01-04-2008
Sjef
 
Posts: n/a
Default Re: choosing a date

OK, I found out that the function does not accept dates as 2008-1-10. When
the date is formatted as 2008-01-10 than the function works flawlessly. I
have finally used the LEAST function to choose between the two dates.
Thanks


"Sjef" <manuals-scripts@planet.nl> schreef in bericht
news:477d31c7$0$25490$ba620dc5@text.nova.planet.nl ...
> Hi there,
> I'm trying to create a sql statement in which a date is compared to
> another date and depending on the comparison one is chosen.
> such as:
>
> if (date_add(cur_date(), interval 30 day) >=
> '$thisDate','$this->date',date_add(cur_date(), interval 30 day)
>
> So: if the current date plus 30 days is larger than thisDate then thisDate
> is used, else the date plus 30 days is used.
> But: it doesn't do what I expected it to do. Can anybody pint out the
> reason. No error message or so ...
>
> Thanks, Sjef
>



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:27 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0