473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dates in MySQL queries

I am trying to do select all of the records in a table where they data
has not expired.

The table contains two fields Subject (varchar(100)) and ExpiryDate
(Date).

I am getting all of the records returned when I execute:

$sql = "select * from tbl where ExpiryDate > " . date("Y-m-d");
mysql_query($sql);

The expiry date in the record I am looking at is 2004-03-25 and the
query that is being executed is:

select * from tbl where ExpiryDate > 2004-03-28

What am I missing? Can anyone recommend a good site to look at that
discusses dates in MySQL queries?

Thanks in advance,
Mark
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)
Jul 17 '05 #1
3 2211
On Sun, 28 Mar 2004 16:54:52 +0100, Mark Stevens <re**@my.sig> wrote:
I am trying to do select all of the records in a table where they data
has not expired.

The table contains two fields Subject (varchar(100)) and ExpiryDate
(Date).

I am getting all of the records returned when I execute:

$sql = "select * from tbl where ExpiryDate > " . date("Y-m-d");
mysql_query($sql);

The expiry date in the record I am looking at is 2004-03-25 and the
query that is being executed is:

select * from tbl where ExpiryDate > 2004-03-28

What am I missing?
Quotes.

2004-03-28 is an arithmetic expression which equals 1978. This isn't a valid
date representation, so it either gets silently turned into the zero-date
0000-00-00, which is less than all the dates in your table, or they're both
turned into strings and compared, which still gives the same result. (I don't
know off the top of my head which approach MySQL takes in this case).

Whereas '2004-03-28' is a string representation of a date, which MySQL can use
to compare with a date field.
Can anyone recommend a good site to look at that
discusses dates in MySQL queries?


http://www.mysql.com/documentation/m...e_calculations
http://www.mysql.com/documentation/m...and_time_types
http://www.mysql.com/documentation/m...time_functions
http://www.mysql.com/documentation/m...tml#Using_DATE

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2
On Sun, 28 Mar 2004 17:05:51 +0100, Andy Hassall <an**@andyh.co.uk> wrote:
2004-03-28 is an arithmetic expression which equals 1978.


1973, even. Bleh :-p

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #3
On Sun, 28 Mar 2004 17:05:51 +0100, Andy Hassall <an**@andyh.co.uk>
wrote:
Quotes.

2004-03-28 is an arithmetic expression which equals 1978. This isn't a valid


Thanks, works fine now.

Regards,
Mark
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bob | last post by:
This little date formating problem is holding me up! Here is the sql query string. ..... WHERE (`work_orders`.`date_closed` > $ > $start_date) AND (`work_orders`.`date_closed` < $end_date)...
0
by: Massimo Fiorentino | last post by:
Hello there! I am a bit of a newbee into the mySQL world and I have a question regarding switching from one DB to another. I have for a couple of years used a very simple CMS-system created by...
0
by: Plymouth Acclaim | last post by:
Hi guys, We have a problem with Dual AMD64 Opteron/MySQL 4.0.18/Mandrake 10 for a very high volume site. We are evaluating the performance on our new server AMD64 and it seems it's slow compared...
2
by: David | last post by:
Hi, I have part of my SQL statement in my asp page as follows: WHERE ((pcbforecast.ShipETA < '31/12/2005') and (products.BBProductName = ....... The problem I am having is that I want the...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
2
by: ameshkin | last post by:
Hi GUys, Im trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work. Basically, if the last comment is...
4
by: Good Man | last post by:
Hi there I have a list of jobs scheduled in a MySQL table, with start dates and end dates, like so: SchedID | JobID | StartDate | EndDate |...
13
by: Ciaran | last post by:
Hi All, Is it faster to have mySql look up as much data as possible in one complex query or to have php do all the complex processing and submit lots of simple queries to the mysql database? ...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.