Display two dates in the same month together

#1

Hi all,

I have dates from a database for example:

2019-03-12
2019-03-16

These i would like to display as:
12-16 March

But if the dates overlap a month:

2019-03-29
2019-04-12

Then it would be displayed as:
39 March - 12 April

Could this be done with some date format function in php?

#2

No, you would need some additional logic, something along the lines of

if (start date and end date are in the same month) {
    // display dates and month name
} else {
    // display dates and months
}
1 Like
#3

I’m thinking they could probably be grouped into months in the database query. Then you would have php output the array data.

1 Like
#4

Same amount of logic, just a question of if you want the database engine lifting or the PHP one lifting.

PHP can do it in-situ with a regex:
preg_replace("/(\d+) (.*?) - (\d+) \2/","\1-\3 \2");

1 Like