# Compare Dates (UTC with Local)

**URL:** <https://discourse.cakephp.org/t/compare-dates-utc-with-local/2893>\
**Category:** Need Help\
**Created:** [July 17, 2017, 9:19am UTC](https://discourse.cakephp.org/t/compare-dates-utc-with-local/2893 "2017-07-17T09:19:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://discourse.cakephp.org/u/andrekat)\
**Post date:** [July 17, 2017, 9:19am UTC](https://discourse.cakephp.org/t/compare-dates-utc-with-local/2893/1 "2017-07-17T09:19:06Z")

</div>

I have got a problem comparing two dates:

First date (see debug upper) is the output of Time::now();  
Second date (see debug lower) is the output of a database field.

![](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/1X/b153fcb99921efb74afa84ed617277ae2ad9ff8a.png)

Now if i check, if the second date “-\>isPast()” it returns false. I think this happens because of the time difference between UTC and Europe/Vienna (+02:00 i guess?).

I tried to set the timezone at the datasource setting -\> “+02:00”, but it makes no difference.

Any suggestions to fix this?

regards,

---

<div class="post-metadata">

**Author:** ![xaphalanx](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xaphalanx/32/575_2.png) [@xaphalanx](https://discourse.cakephp.org/u/xaphalanx)\
**Post date:** [July 17, 2017, 12:59pm UTC](https://discourse.cakephp.org/t/compare-dates-utc-with-local/2893/2 "2017-07-17T12:59:26Z")

</div>

To make the camparison I would take the euro/vienna timestamp convert it to UTC and then compare. Does that help? Not sure what you mean by at “datasource”

---

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://discourse.cakephp.org/u/andrekat)\
**Post date:** [July 18, 2017, 7:11am UTC](https://discourse.cakephp.org/t/compare-dates-utc-with-local/2893/3 "2017-07-18T07:11:37Z")

</div>

well, actually both are Europe/Vienna Timestamps … if i’d convert the first to UTC, the time would be 09:14:29 … i just want to compare 11:14:29 and 10:50.05 … but it wont work 😓

---

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://discourse.cakephp.org/u/andrekat)\
**Post date:** [July 24, 2017, 1:24pm UTC](https://discourse.cakephp.org/t/compare-dates-utc-with-local/2893/4 "2017-07-24T13:24:28Z")

</div>

any one else an idea?

---

<div class="post-metadata">

**Author:** ![Diego](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/diego/32/296_2.png) [@Diego](https://discourse.cakephp.org/u/Diego)\
**Post date:** [July 24, 2017, 5:05pm UTC](https://discourse.cakephp.org/t/compare-dates-utc-with-local/2893/5 "2017-07-24T17:05:00Z")

</div>

try to set cake to work with your locale/timezone:

```
in config/app.php:
    'App' => [
                'defaultLocale' => env('APP_DEFAULT_LOCALE', 'UR-LOCALE-CODE')

```

in config/bootstrap.php:

```
date_default_timezone_set('Europe/Vienna');
\Cake\I18n\I18n::locale('UR-LOCALE-CODE');

Type::build('time')->useImmutable();
Type::build('date')->useImmutable()->useLocaleParser();
Type::build('datetime')->useImmutable()->useLocaleParser();
Type::build('timestamp')->useImmutable();

```

now both dates should be in the same timezone and you may proced the compare
