怎样用php实现两个时间相减,得到相差的天数

//第一种方法

$time1 = mktime(10,20,30,2,5,2000); //2000-2-5 10:20:30
$time2 = mktime(18,30,20,5,2,2000); //2000-5-2 18:30:20

//第二种方法

$time1= ‘2010-7-1‘;
$time2=‘2010-7-8‘;
//计算两者差值
$days=abs((strtotime($date1)-strtotime($date2))/86400);
$diff = (int)(($time2-$time1)/(24*3600));
echo "$time2 和 $time1 的时间差为:" . $diff . "天
";

时间: 2024-07-30 15:46:47

怎样用php实现两个时间相减,得到相差的天数的相关文章

oracle 两个时间相减

oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认的是天数*24*60*60 为相差的秒数 --MONTHS_BETWEEN(date2,date1) 给出date2-date1的月份 SQL> select months_between('19-12月-1999','19-3月-1999') mon_between from dual; MON_

oracle两时间相减得到相差的时间

1.months_between(date1,date2);date1和date2相减得到相差的月份. select months_between(to_date('2015-05-11','yyyy-MM-dd'),to_date('2015-04-11','yyyy-MM-dd')) from dual :相差一个月. 2.ceil(date1-date2);date1-date2相减得到相差的天数 select ceil(To_date('2015-05-11 00:00:00' , 'y

C#两个时间相减

原文地址:http://www.jb51.net/article/60177.htm using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { class Program { static void Main(string[] args) { DateTime t1 = DateTime.Parse("2007-01-01"); DateT

两个时间相减

<1> using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { class Program { static void Main(string[] args) { DateTime t1 = DateTime.Parse("2007-01-01"); DateTime t2 = DateTime.Parse("200

MySQL两个时间相减

SELECT TIMESTAMPDIFF(MONTH,'2009-10-01','2009-09-01'); interval可是: SECOND 秒 SECONDS MINUTE 分钟 MINUTES HOUR 时间 HOURS DAY 天 DAYS MONTH 月 MONTHS YEAR 年 YEARS 原文地址:https://www.cnblogs.com/bulrush/p/10397168.html

Java计算年月日时分秒时间差(两个时间相减)

//测试主方法  public static void main(String[] args) {          Date currentTime = df.parse("2004-03-26 13:31:40");   //当前系统时间             Date firstTime = df.parse("2004-01-02 11:30:24");     //查询的数据时间          String str=getTime(currentTi

Oracle 时间相减得出毫秒、秒、分、时、天,,【转】

http://blog.csdn.net/redarmy_chen/article/details/7351410 oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认的是天数*24*60*60 为相差的秒数 --MONTHS_BETWEEN(date2,date1) 给出date2-date1的月份 SQL> select months_betwe

两个时间戳相减

两个时间戳相减就是相差的毫秒 { "task_name": "VERTEX_LABEL:1:node", "task_progress": 0, "task_create": 1577969459291, 13位,毫秒级别 "task_status": "running", "task_update": 1577969459291, "task_retrie

JAVA基础学习之final关键字、遍历集合、日期类对象的使用、Math类对象的使用、Runtime类对象的使用、时间对象Date(两个日期相减)

1.final关键字和.net中的const关键字一样,是常量的修饰符,但是final还可以修饰类.方法.写法规范:常量所有字母都大写,多个单词中间用 "_"连接. 2.遍历集合ArrayList<Integer> list = new ArrayList<Integer>();list.add(1);list.add(3);list.add(5);list.add(7);// 遍历List方法1,使用普通for循环:for (int i = 0; i <