Php+mysql how to store and read formatted time.

Source: Internet
Author: User
Note: You only need to store, read, and judge the time, not including the date.
Such as
Start time: 08:30:00
End Time: 18:00:00
Enter the time in the form as above, can you store it in the MySQL database with an int type, and print it in PHP?
You can also determine whether the current time of the server is between start and end.


Reply to discussion (solution)

Before you save the database, turn the strtotime into 10 digits and then judge the direct ratio.

The string can be stored directly, and it can be compared with the current time.

Storage and read solved, how can I tell? Can you make it a little more specific?

How you store and read, it's best to post code for analysis.

Save:
$_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;
$time 1=date ("H:i:s", $info [' time1 ']);
$time 2=date ("H:i:s", $info [' time2 ']);

How to determine whether the current server time is:
$time 1
$time 2
Between.

$current = Date ("H:i:s"), if ($current > $time 1 && $current < $time 2) {     echo ';} else{     Echo ' non-between ';}

$current = Date ("H:i:s"), if ($current > $time 1 && $current < $time 2) {     echo ';} else{     Echo ' non-between ';}


I generally use this method date ("H:i:s") so the output of the result is the landlord to the result
  • 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.