Solved

Date comparison...database query

Posted on 2002-05-16
6
260 Views
Last Modified: 2012-06-27
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
===
0
Comment
Question by:slok
6 Comments
 
LVL 6

Expert Comment

by:andreif
ID: 7013465
maybe you shoud better ask this in Oracle topic?
0
 
LVL 8

Expert Comment

by:us111
ID: 7013604
oracle format is :
YYYY-MM-DD
so try
$sdate = sdate_yy."-".sdate_mm."-".sdate_dd;
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7013626
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.
0
 
LVL 3

Author Comment

by:slok
ID: 7015359
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.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 11688190
Submitted to PAQ with points refunded (50)

DarthMod
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I show metrics with PHP or Javascript 6 32
check mysql insert 12 26
Ajax and PHP 9 29
PHP 5.6 and 7.x 4 21
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question