I need assistance with formatting a date string. I have a JSON object which contains the elements “start_date” and “end_date”. These elements contain date information in a string such as so:
I have created this method to format my start_date and end_date:
def format_date(date) date.to_time.strftime('%b %d') end
What this method does is to format the date into this format of:
This method helps me print the start_date and end_date into the form:
"Jul 15 to Jul 27"
What I want, is to have my dates formatted in the form of:
"15 - 27 July 2015" #If the two dates fall within the same month "15 July - 27 Aug 2015" #If the two dates fall into separate months
Could anyone assist me in writing such a ruby method?