• I’m using the 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)
  • 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 3 years, 8 months ago by polarracing.
    Thread Starter iantresman

    (@iantresman)

    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.

    Found this one in this forum. Its not in the docs.

    Thread Starter iantresman

    (@iantresman)

    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.

    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

    (@iantresman)

    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

    (@iantresman)

    @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).

    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 3 years, 8 months ago by polarracing.
    • This reply was modified 3 years, 8 months ago by polarracing.
    Thread Starter iantresman

    (@iantresman)

    So that’s how. @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.