By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,637 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,637 IT Pros & Developers. It's quick & easy.

date difference calculation in PHP

P: 34
hi,
I don't know how to subtract two date. Date format is (Y.m.d).
Jan 22 '07 #1
Share this Question
Share on Google+
4 Replies


iam_clint
Expert 100+
P: 1,208
[font=Arial]http://www.w3schools.com/vbscript/func_datediff.asp[/font]


of course this is vbscript but I am pretty sure you can use the datediff() function in php aswell.
Jan 22 '07 #2

P: 34
[font=Arial]http://www.w3schools.com/vbscript/func_datediff.asp[/font]


of course this is vbscript but I am pretty sure you can use the datediff() function in php aswell.
Thaks,I'll try convert PHP code
Jan 22 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
First convert the dots to hyphens. Then recalculate to sceonds, cal the difference in seconds and re-format to days. This is it[php]<?php
// init values
$datefrom = '2006.7.12';
$dateto = '2006.7.20';
// convert dots to hyphens
$datefrom = str_replace('.','-', $datefrom);
$dateto = str_replace('.','-', $dateto);
// calc to seconds
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
// calc difference in seconds
$difference = $dateto - $datefrom;
// reformat to days
$datediff = floor($difference / 86400);
// print result
echo "Difference is: $datediff days";
?>[/php]
Ronald :cool:
Jan 22 '07 #4

P: 17
Use Callender function in php GregorianToJD



$x0 = GregorianToJD($m0,$d0,$y0);
$x1 = GregorianToJD($m1,$d1,$y1);

$diff = $x1 - $x0;

it's very simple
Feb 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.