How to store and read the formatting time in PHP + MYSQL. Note: You only need to store, read, and determine the time, excluding the date ..
For example
Start time: 08: 30: 00
End time: 18: 00: 00
Input the time in the above format in the form. can I store the time in the int type in the MYSQL database? how can I use PHP to read and print the time?
You can also determine whether the current time of the server is between the start and end.
Reply to discussion (solution)
Before saving the database, use strtotime to convert it into a 10-digit number, and then determine the direct ratio.
You can directly store strings and compare them with the current time.
Storage and reading are solved. how can I judge? Can it be more specific?
How do you store and read data? it is best to paste the code for analysis.
Storage:
$ _ POST ['time1'] = '08: 00: 08 ';
$ _ POST ['time2'] = '16: 00: 08 ';
$ Data ['time1'] = strtotime (in ($ _ POST ['Time']);
$ Data ['time2'] = strtotime (in ($ _ POST ['Time']);
Read:
$ Info ['time1'] = 1395100808;
$ Info ['time2'] = 1395129608;
$ Time1 = date ("H: I: s", $ info ['time1']);
$ Time2 = date ("H: I: s", $ info ['time2']);
Determine whether the current server time is:
$ Time1
$ Time2
.
$ Current = date ("H: I: s"); if ($ current> $ time1 & $ current <$ time2) {echo ';} else {echo 'non-interval ';}
$ Current = date ("H: I: s"); if ($ current> $ time1 & $ current <$ time2) {echo ';} else {echo 'non-interval ';}
I usually use this method date ("H: I: s") to output the result, which is what the landlord wants.