How to store and read the formatting time in PHP + MYSQL.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.