Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > PHP & DateTime query
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 10th June 23:08
jay
External User
 
Posts: 1
Default PHP & DateTime query



Anyone know of any simple tutorials or how to perform a MySQL query with PHP
on the DateTime field?

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

I would like to be able to perform the following queries:

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

Thanks greatly!
  Reply With Quote


  sponsored links


2 10th June 23:08
codik
External User
 
Posts: 1
Default PHP & DateTime query



Good day.

I don't understand why You are using DATETIME field, when You want
finding data only by date. My opion is. You create a DATE field and You
use for 1. query:
SELECT * FROM table WHERE date = '2006-01-01'

And for 2. query:
SELECT * FROM perform1 WHERE date >= '2006-01-01' AND date <=
'2006-01-03'

--
When my English is bad, sorry.
  Reply With Quote
3 10th June 23:08
jay
External User
 
Posts: 1
Default PHP & DateTime query


No problems ...

I have to use the DATETIME field, because that is what they have in place
already ...

Will try your code out - thanks!
  Reply With Quote
4 11th June 01:39
rwagener11
External User
 
Posts: 1
Default PHP & DateTime query


This is what I have used.

(order_date >= '$start_date 00:00:00' and order_date <= '$finish_date
23:59:59')

You might have a conflict with the PM and AM.

Let me know if this helps
  Reply With Quote
5 11th June 02:23
codik
External User
 
Posts: 1
Default PHP & DateTime query


rwagener11@gmail.com napísal(a):

Format is YYYY-MM-DD HH:MM:SS. Check it. There is a 24-hours format,
there isn't any PM or AM.
  Reply With Quote
6 11th June 02:23
nc
External User
 
Posts: 1
Default PHP & DateTime query


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...


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;

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

Cheers,
NC
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666