Title: Changing the date format
Last modified: March 30, 2021

---

# Changing the date format

 *  [iantresman](https://wordpress.org/support/users/iantresman/)
 * (@iantresman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/)
 * I’m using the [Modern Events Calendar Lite](https://wordpress.org/plugins/modern-events-calendar-lite/)(
   MEC). When I display an MEC event date using [field mec_start_date], it displays
   as: 2021-10-21.
 * How can I get this to display just the year. I tried [field mec_start_date format
   =Y] but it is unchanged.
 * Ultimately, I want to calculate and display an anniversary using the math module,
   to show how many years it has been since the year 2000. eg.
 * Number of years ago is: [calc] [field mec_start_date format=Y] – 2000[/calc] 
   to show: 21 years.
 * Any pointers?

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [polarracing](https://wordpress.org/support/users/polarracing/)
 * (@polarracing)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14258180)
 * This field is not recognized as date. CCS sees it as string.
 * Use `[format split='-' part=X]` to separate the date parts as vars and do what
   you like with them.
    -  This reply was modified 5 years, 1 month ago by [polarracing](https://wordpress.org/support/users/polarracing/).
 *  Thread Starter [iantresman](https://wordpress.org/support/users/iantresman/)
 * (@iantresman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14260583)
 * Many thanks for that. Is this documented anywhere, I couldn’t find it. Would 
   be nice to see whether I am missing any other options.
 *  [polarracing](https://wordpress.org/support/users/polarracing/)
 * (@polarracing)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14260719)
 * Found this one in this forum. Its not in the docs.
 *  Thread Starter [iantresman](https://wordpress.org/support/users/iantresman/)
 * (@iantresman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14260781)
 * Thank you for the pointer, but I’m still not getting it. Let’s suppose I have:
   [
   field myfield] which displays 2021-03-31.
 * How do I tell [format split=’-‘ part=X] to split “myfield”? And what does “part
   =X” do, it looks neither like the original field, not the split field. Do I have
   to store “myfield” in a variable first?
 * Sorry to be so dense. I’d happily put together some documentation if I understood
   it.
 *  [polarracing](https://wordpress.org/support/users/polarracing/)
 * (@polarracing)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14260799)
 * Straight foreward:
 * `[format split='-' part=1][field myfield][/format]` – gives you the year.
    `[
   format split='-' part=2][field myfield][/format]` – gives you the month. `[format
   split='-' part=3][field myfield][/format]` – gives you the day.
 *  Thread Starter [iantresman](https://wordpress.org/support/users/iantresman/)
 * (@iantresman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14260927)
 * Ah! Easy when you know how. Just to be thorough, if I now want to store the year
   in a variable so that I can use it, this works (note that myfield=2021-03-01):
 *     ```
       [set year][format split='-' part=1][field myfield][/format][/set]
       [set month][format split='-' part=2][field myfield][/format][/set]
       [set day][format split='-' part=3][field myfield][/format][/set]
       The year is: [get year] month: [get month] day: [get day]
       ```
   
 * I can now calculate and show that 2000 was `[calc][get year]-2000[/calc]` years
   ago.
 *  Thread Starter [iantresman](https://wordpress.org/support/users/iantresman/)
 * (@iantresman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14260950)
 * [@polarracing](https://wordpress.org/support/users/polarracing/) thank you again
   for your help. I’m going to push my luck, is there a way to compare two dates?
 * If myfield=2021-03-01, then
 * myfield – 2000-03-01 = 21 years. But
    myfield – 2000-04-01 = 20 years (and 11
   months).
 *  [polarracing](https://wordpress.org/support/users/polarracing/)
 * (@polarracing)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14261004)
 * This calculates an age from a birthday. Should give you some idea. You would 
   need to change the code to use your date-parts.
 *     ```
       [set month][calc][today format=md] - [format date=md][get my_field][/format][/calc][/set]
       [if var=month compare=less value='0']
       [calc][today format=Y]-[format date=Y][get my_field][/format]-1[/calc]
       [else]
       [calc][today format=Y]-[format date=Y][get my_field][/format][/calc]
       [/if]
       ```
   
    -  This reply was modified 5 years, 1 month ago by [polarracing](https://wordpress.org/support/users/polarracing/).
    -  This reply was modified 5 years, 1 month ago by [polarracing](https://wordpress.org/support/users/polarracing/).
 *  Thread Starter [iantresman](https://wordpress.org/support/users/iantresman/)
 * (@iantresman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14261076)
 * So that’s how. [@polarracing](https://wordpress.org/support/users/polarracing/)
   you have been a star. 🙂

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Changing the date format’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-shortcode_766976.svg)
 * [Custom Content Shortcode](https://wordpress.org/plugins/custom-content-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-shortcode/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [iantresman](https://wordpress.org/support/users/iantresman/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/changing-the-date-format-9/#post-14261076)
 * Status: not resolved