slok
asked on
Date comparison...database query
I have a form which passes 3 values (day, month, year).
I concat. the 3 values together..
$sdate = sdate_dd + "-" + sdate_mm + "-" + sdate_yy;
how can I do a SQL query to retrieve records less than this date? I am using ORacle database.
my current query is as follows:
==
$query = "select * from tableA where sdate < $sdate";
==
but it complains with the following message
==
OCIStmtExecute: ORA-01861: literal does not match format string
===
I concat. the 3 values together..
$sdate = sdate_dd + "-" + sdate_mm + "-" + sdate_yy;
how can I do a SQL query to retrieve records less than this date? I am using ORacle database.
my current query is as follows:
==
$query = "select * from tableA where sdate < $sdate";
==
but it complains with the following message
==
OCIStmtExecute: ORA-01861: literal does not match format string
===
maybe you shoud better ask this in Oracle topic?
oracle format is :
YYYY-MM-DD
so try
$sdate = sdate_yy."-".sdate_mm."-". sdate_dd;
YYYY-MM-DD
so try
$sdate = sdate_yy."-".sdate_mm."-".
You should also check to make sure that the century is present in the year.
If you have a form with this in then you could ask for the century as a seperate field (select 19 and 20) and year (select 00 to 99).
Richard.
If you have a form with this in then you could ask for the century as a seperate field (select 19 and 20) and year (select 00 to 99).
Richard.
ASKER
I found the answer.
Apparently, when constructing the query statement in PHP, I need to insert quotes for the date variable and also make use of the to_date function
eg
===
$query = "select * from tableA where sdate < to_date('$sdate', 'dd-mm-yyyy')";
==
Note: take note of the single quotes around $sdate and also the use of to_date function.
Thanks all for the help. I will delete this question in one week's time.
Apparently, when constructing the query statement in PHP, I need to insert quotes for the date variable and also make use of the to_date function
eg
===
$query = "select * from tableA where sdate < to_date('$sdate', 'dd-mm-yyyy')";
==
Note: take note of the single quotes around $sdate and also the use of to_date function.
Thanks all for the help. I will delete this question in one week's time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.