Click here to Skip to main content
15,075,944 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to select data between two dates, but I am not getting the Right PHP, MYSQL functions to perform this step.

I have some questions regarding my problem.

1. Which Format/data type should I choose to store dates in MySQL database?
2. Which PHP function should I use to handle dates?
3. Which MySQL function should I use in SQL Queries to get the precise data between two dates.

Please guide me about that?


Note: If there are some other important things about handling dates in PHP/MySQL, please give me your precious guideline.
Posted

1 solution

You can use time(); to see how php will format a date. You can echo out the values if you want from each of the code below to get a feel for how it works. Php is well documented, and should be very easy to find

$date = time();
$day = date('d',$date);
$month = date('m',$date);
$year = date('Y',$date);


php date page[^]

I believe the insert format for mysql is yyyy-mm-dd, while date time is the same with HH:MM:SS appended to it. You can use a BETWEEN on dates to limit the search.

Mysql is also very well documented on their own website.

MySql docs[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900