Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'd like to check if to Zend_Date datetimes are on the same day. How can I do that?

$date1 = new Zend_Date('2011-11-14 10:45:00');
$date2 = new Zend_Date('2011-11-14 19:15:00');
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
443 views
Welcome To Ask or Share your Answers For Others

1 Answer

$date1 = new Zend_Date('2011-11-14 10:45:00');
$date2 = new Zend_Date('2011-11-14 19:15:00');
if ($date1->compareDay($date2) === 0) {
    echo 'same day';
}

Also see the chapter on Comparing Dates with Zend Date

On a sidenote, I strongly encourage you to verify if you have the need for Zend_Date. Do not use it just because it is part of ZF. Most of what Zend_Date does can be achieved faster and more comfortably with native DateTime as well:

$date1 = new DateTime('2011-11-14 10:45:00');
$date2 = new DateTime('2011-11-14 19:15:00');
if ($date1->diff($date2)->days === 0) {
    echo 'same day';
}

EDIT after comments
If you want to compare whether it's the same date just do

$date1->compareDate($date2)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...