/    Sign up×
Community /Pin to ProfileBookmark

How to fine dates in between dates (Start_date 2008-10-25 and End_date 2008-11-10)

How to fine dates in between dates. I have start_date 2008-10-25 and end_date 2008-11-10. I want dates given between dates. How to find this. Help me. ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SodbusterNov 19.2008 — [code=php]if (($check_date > $start_date) && ($check_date < $end_date)) {
echo 'OK';
}[/code]
Copy linkTweet thisAlerts:
@MindzaiNov 19.2008 — Maybe I read the question wrong but I read it as wanting to get a list of all dates between the two dates?

If so the following should do that.

[code=php]<?php

$start_date = '2008-10-25';
$end_date = '2008-11-10';

$days = round((strtotime($end_date) - strtotime($start_date)) / 86400);

$start_parts = explode('-', $start_date);
for ($i=0 ; $i<=$days ; $i++) {
echo date('Y-m-d', mktime(0, 0, 0, $start_parts[1], $start_parts[2]+$i, $start_parts[0])) . '<br />';
}

?>[/code]


That will output:

[CODE]2008-10-25
2008-10-26
2008-10-27
2008-10-28
2008-10-29
2008-10-30
2008-10-31
2008-11-01
2008-11-02
2008-11-03
2008-11-04
2008-11-05
2008-11-06
2008-11-07
2008-11-08
2008-11-09
2008-11-10[/CODE]
Copy linkTweet thisAlerts:
@SodbusterNov 19.2008 — I'm the one who misread, of course. ?

This should also work:[code=php]$start_date = '2008-10-25';
$end_date = '2008-11-10';
$start_ts = strtotime($start_date);
$end_ts = strtotime($end_date);
$new_ts = $start_ts;
while (($new_ts = strtotime('+1 day', $new_ts)) < $end_ts) {
echo date('Y-m-d', $new_ts) . '<br />';
}[/code]
[CODE]2008-10-26
2008-10-27
2008-10-28
2008-10-29
2008-10-30
2008-10-31
2008-11-01
2008-11-02
2008-11-03
2008-11-04
2008-11-05
2008-11-06
2008-11-07
2008-11-08
2008-11-09[/CODE]
(Dates are [I]between[/I] 2008-10-25 and 2008-11-10.)
×

Success!

Help @jsaravananj 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 5.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...