You are here: Re: PHP & DateTime query « All PHP « IT news, forums, messages
Re: PHP & DateTime query

Posted by NC on 03/13/06 18:13

Jay wrote:
>
> MySQL Database has DateTime Values (Example: 2/9/2006 3:30:06PM)

Er, no. A MySQL database has a DateTime value that looks like this:

2006-02-09 15:30:06

You can think of it as text, and when you sort it as text, it sorts in
a correct chronological order...

> I would like to be able to perform the following queries:
>
> 1: specific date (show all records on that date)

SELECT * FROM mytable WHERE myDTfield = '2006-02-09%';

The addition of % mask will ensure that all records dated Feb. 9, 2006
are shown.

Alternetively, you could try:

SELECT * FROM mytable
WHERE
MONTH(myDTfield) = 2
AND
DAY(myDTfield) = 9;

> 2. range of dates (show all records in between 2 dates. example: form
> 1/1/2006 to 1/3/2006)

SELECT * FROM mytable
WHERE
myDTfield >= '2006-01-01 00:00:00'
AND
myDTfield <= '2006-01-03 23:59:59';

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация