/    Sign up×
Community /Pin to ProfileBookmark

date difference

i have two textfields, user select dates from a popup calender and and wants to know the days between these two dates while using PHP

can u buddy help me?????

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@aussie_girlMar 06.2007 — have a look at the DateDiff() function
Copy linkTweet thisAlerts:
@NightShift58Mar 06.2007 — datediff() is a MySQL function, not PHP.

[code=php]<?php
$ts_date1 = strtotime($date1);
$ts_date2 = strtotime($date2);
$ts_diff = $ts_date2 - $td_date1; // diff in seconds
?>[/code]
Copy linkTweet thisAlerts:
@aussie_girlMar 06.2007 — OOPS, well that was embarrassing I always assume people are using databases, my bad

datediff() is a MySQL function, not PHP.

[code=php]<?php
$ts_date1 = strtotime($date1);
$ts_date2 = strtotime($date2);
$ts_diff = $ts_date2 - $td_date1; // diff in seconds
?>[/code]
[/QUOTE]
Copy linkTweet thisAlerts:
@mahfoozauthorMar 07.2007 — thanks for replying

but the problem ist that i got time from textfields and it PHP takes them as string and therefore i m facing difficulties to calculate day differences between two dates:
Copy linkTweet thisAlerts:
@jignesh1Mar 07.2007 — the strtotime() function should convert the date to time

i think that wat NightShift58 is trying to say
<i>
</i>$ts_date1 = strtotime($_POST['date1']);
$ts_date2 = strtotime($_POST['date2']);
Copy linkTweet thisAlerts:
@NightShift58Mar 07.2007 — the strtotime() function should convert the date to time

i think that wat NightShift58 is trying to say
<i>
</i>$ts_date1 = strtotime($_POST['date1']);
$ts_date2 = strtotime($_POST['date2']);
[/QUOTE]
No, actually not. Usually, dates selected in <SELECT> come in 3 parts: month, day and year. If you want my thoughts in detail, it would be this:[code=php]<?php
$date1 = $_POST['year1'] . "-" . $_POST['month1'] . "-" . $_POST['day1'];
$date2 = $_POST['year2'] . "-" . $_POST['month2'] . "-" . $_POST['day2'];
$ts_date1 = strtotime($date1);
$ts_date2 = strtotime($date2);
?>[/code]
But the OP will have to know how and what to concatenate because you and I can only assume things.
×

Success!

Help @mahfooz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...