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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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
"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. > > > |
|
|||
|
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! |
|
|||
|
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 > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|