473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

date difference calculation in PHP

hi,
I don't know how to subtract two date. Date format is (Y.m.d).
Jan 22 '07 #1
4 3951
iam_clint
1,208 Expert 1GB
[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
[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
4,258 Expert 4TB
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
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

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

Similar topics

4
by: Manny Chohan | last post by:
Hi Can anyone tell me how i can calculate yesterday date using asp? Thanks manny
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
4
by: qtip | last post by:
I have a simple table the has First Name , Last Name, SSN, Date&Time. I have a report that will show all this information but I would like to put in at calculation to tell the difference between 2...
2
by: Gershon | last post by:
I have a simple table including First Name, Last Name, Start Date. I need to create a report listing First, Last and the number of days since Start Date. The First and Last names are easy. How do I...
2
by: Issac Gomez | last post by:
IN VB.Net, you can use the DateDiff method to calculate the difference between 2 days. How do you do this in C#? I want to find the number of days between 2 dates. I there a 0 days, then I want to...
3
by: Reney | last post by:
I am using Access in my project. In one of the forms, I am calling two tables, and two of the columns have date/time type, namely "ClockIn" and "ClockOut". I created a dataset and filled the...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
10
by: DontellTrevell via AccessMonster.com | last post by:
HELP!!....I need to calculate the numer of days elapsed between two field. But, the date format is YYYYMMDD. How can i accomplsh this? -- Dontell Trevell Message posted via AccessMonster.com...
15
by: sumhungl0 | last post by:
im not sure how to even start this. im using access 03 to build a db to store my water district meter readings. i have 2 tables so far, 1 consumer info and 2 monthly meter readings. i need a query...
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.