English 中文(简体)
PHP两度的差异
原标题:difference between two times in PHP
  • 时间:2011-01-05 14:27:47
  •  标签:
  • php
  • mysql

Hi All
im trying to build a simple form that the user use it to enter his leave request.
the form contains from time input field and to time input field,and these two filds will contains values in this syntax: from time: 15:59 pm to time: 16:59 pm

i have two questions:
1. what is the Datatype that i should use to store p.m and am in the record in mysql database, and not only the time?(i try to use Time,DateTime Date) but these datatypes only stores the time without p.m,a.m
2. what is the best way to calculate the diffrence between these two times?
Thank You

问题回答

If you are comparing dates/times I find it easiest to work with a timestamp. There are tons of date functions in PHP if it s just to output the date in the format you want have a look at date functions

数据库中储存时间的最佳方式是24小时,使用PHP s代码<>date,以安排你用AM或PM显示时间。

相比之下,我建议研究strtotime的功能。 时间将以UNIX(秒)方式回来。 然后,你可以比较哪些时间大于或少于另一个时间,或甚至进行基本的数学操作(如确定每小时二秒,然后按60分辨率等)。

仅将其作为一个时间序列储存,在你产出时,你可以自动增加餐桌。

www.un.org/Depts/DGACM/index_french.htm

a. 仅使用胎体和子体的二分体:

<编码>印(体字(16:59 ) - strtotime(15:59 );

1) This doesn t make any sense - the database stores a representation of an exact instant in time, not an ambiguous 12 hour format with no am/pm. Regardless of how the db is storing it, you can just calculate the am or pm:

<?php
$am_pm = date( a , $timestamp);
?>

或更妥善地利用你的时间:

SELECT DATE_FORMAT(date_field,  %p )

2) 为此,您可使用网站date_diff或我的sql:

SELECT DATEDIFF(date_one, date_two)

当你重新使用24种格式时, Sto忙。 页: 1 时间/时间应当足以完成你重新努力的工作。 然后,你可以把体力回12小时,用上/平。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签