I have two Advanced Custom Fields datepicker fields in Wordpress – a starting date and a finishing date. These are in the back end, so that my client can add/edit posts and give them a date range.
Dates below are given as dd/mm/yyyy (I'm Australian).
I need to compare the two dates to come up with a nice date range for display on the front end. It needs to:
Check to see whether the two dates are the same, in which case it should just output one date (e.g. start date is 20/7/2015, finish date is 20/7/2015, so output is 20 July 2015).
If the two dates are different but in the same month, output as dd – dd mm yyyy (e.g. start date is 10/3/2015, finish date is 25/3/2015, so output is 10 – 25 March 2015).
If the two dates are in different months but the same year, output as dd mm – dd mm yyyy (e.g. start date is 18/4/2015, finish date is 3/5/2015, so output is 18 April – 3 May 2015).
Finally, if the two dates are in different years, output as dd mm yyyy – dd mm yyyy (e.g. start date is 8/11/2015, finish date is 6/2/2016, so output is 8 November 2015 – 6 February 2016).
I can do 1 and 4 but lack the coding skills to manage 2 or 3.
I'm very surprised I couldn't find this question on SO, so if I've overlooked a duplicate please point me in the right direction.
Thanks.