Page 1 of 1

Format of Month

Posted: Sun 12 Jul 2015 9:27 pm
by Big Daddy
Hi Everyone,
Have been changing some php templates to accomodate the new formatting of Date / Time in MX. However, I came across a slight problem when using the "M" format. I expected this to return the month as a single digit i.e. "7" for July but it returns 01 July.
Have scoured the forum and the wiki but cant find an answer unfortunately.

I did a little php script to check other date formats to make sure I understood and all the results seem to be as i expected except the "M" (first in the list). Am I doing something wrong or does anybody know where I can look for the answer.

I went back to my version of 1.9.4 and the 'm' formatting qould return a single digit i.e. "7"

Results of my test below

$MonthTempHD = "<#MonthTempHD format="M">"; Returns "1 July";
$MonthTempHD = "<#MonthTempHD format="MM">"; Returns "07";
$MonthTempHD = "<#MonthTempHD format="MMM>"; Returns "Jul";
$MonthTempHD = "<#MonthTempHD format="MMMM">"; Returns "July";
$MonthTempHD = "<#MonthTempHD format="d">"; Returns "01/07/2015";
$MonthTempHD = "<#MonthTempHD format="dd">"; Returns "01";
$MonthTempHD = "<#MonthTempHD format="ddd">"; Returns "Wed";
$MonthTempHD = "<#MonthTempHD format="dddd">"; Returns "Wednesday";
$MonthTempHD = "<#MonthTempHD format="D">"; Returns "01 July 2015";
$MonthTempHD = "<#MonthTempHD format="yy">"; Returns "15";
$MonthTempHD = "<#MonthTempHD format="yyyy">"; Returns "2015";

Thanks
Andy

Re: Format of Month

Posted: Sun 12 Jul 2015 9:54 pm
by mcrossley
As you have found a single "M" on its own is taken as a 'standard format' string, and returns "dd Month" (or your localisation). Whereas a single M as part of a format string with other custom format specifiers returns the month as a digit with no zero padding.

https://msdn.microsoft.com/en-us/librar ... _Specifier

Edit: I see Steve has supplied the answer below as usual. I didn't spot the link to using single character custom strings :oops:

Re: Format of Month

Posted: Sun 12 Jul 2015 10:00 pm
by steve
The MX announcement post has links to the Microsoft documentation for the date and time format strings ("standard" and "custom"). If you look at the description for the "M" custom format string (the month number with no leading zero) on the linked page - https://msdn.microsoft.com/en-us/librar ... _Specifier you will see that it says:

If the "M" format specifier is used without other custom format specifiers, it is interpreted as the "M" standard date and time format specifier. For more information about using a single format specifier, see Using Single Custom Format Specifiers later in this topic.

And the topic that links to ("Using Single Custom Format Specifiers") explains that if you want it to be interpreted as a custom format string rather than a standard format string, you should include a space before or after the specifier, or include a percent ("%") format specifier before the single custom date and time specifier.

In other words, <#MonthTempHD format="%M"> will currently return "7".

Re: Format of Month

Posted: Mon 13 Jul 2015 7:32 am
by Big Daddy
Hi Steve / Mark,
Thank you for the explanation. I hadn't realised that a single "M" was treated as a custom string and even though I read the MSDN documents I must have missed the concept. I also got a little confused when I looked at the wiki page on the differences between the formats in Cumulus 1 and MX where it said that an "M" returned the month as a single number as does the MX announcement post so assumed the "M" was all I needed.

Solved my problem again. Appreciate the support.

Andy

Re: Format of Month

Posted: Mon 13 Jul 2015 7:37 am
by steve
Big Daddy wrote:I also got a little confused when I looked at the wiki page on the differences between the formats in Cumulus 1 and MX where it said that an "M" returned the month as a single number as does the MX announcement post so assumed the "M" was all I needed.
Sorry - when I created the table in the announcement, I hadn't considered that someone might want just the month number. I've changed the part where it mentions single characters being treated as standard strings to explicitly mention the percent prefix.

Re: Format of Month

Posted: Mon 13 Jul 2015 8:32 am
by Big Daddy
I am using one of the Weather By You templates as my "base" and the single month number is used to pull in data from an array....as far as I can see. The other data used in the template also needs changing to the MX format but I think I have it all sorted now I have the "%M" sorted.

Many Thanks
Andy