0
votes

I have 2 values stored in a database. One is a startdate, the other an enddate.

Now when the Year, month and date of the 2 are equal. I would like the enddate to only show the time.

For example

maandag 16 juni 14:06 tot maandag 16 juni 14:15

would be

maandag 16 juni 14:06 tot 14:15.

I'm pretty new at PHP. I've tried the following statement, but i'm pretty sure it's incorrect:$

<?php if($item->startdate("Ymd") == ($item->enddate("Ymd"))): ?>

The type of the values are DateTime

3
what is the type of the values stored in the database? String or DateTime - kpp
The type of the values are DateTime - user3481441

3 Answers

0
votes

You could also try using the substr-function, only comparing portions of the variables:

if(substr($item->startdate, 0, 10) == substr($item->enddate, 0, 10))

Here we compare the first ten characters (YYYY-MM-DD) of $item->startdate and $item->enddate.

0
votes
<?php if(date('Y-m-d',strtotime($item->startdate) == date('Y-m-d',strtotime($item->enddate))) : ?>
0
votes

Try

if(date('Ymd',strtotime($item->startdate)) == date('Ymd',strtotime($item->enddate))) :

The date function should take almost any data format and reformat it to the format you give it i.e. 'Ymd'

PHP Manual for the date() function