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
Welcome to the Cumulus Support forum.
Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080
Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080
Format of Month
Moderator: mcrossley
- mcrossley
- Posts: 14388
- Joined: Thu 07 Jan 2010 9:44 pm
- Weather Station: Davis VP2/WLL
- Operating System: Bullseye Lite rPi
- Location: Wilmslow, Cheshire, UK
- Contact:
Re: Format of Month
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
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
Last edited by mcrossley on Sun 12 Jul 2015 10:14 pm, edited 1 time in total.
- steve
- Cumulus Author
- Posts: 26672
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: Format of Month
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".
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".
Steve
-
Big Daddy
- Posts: 270
- Joined: Tue 10 Sep 2013 8:40 pm
- Weather Station: Ecowitt GW1000 / various sensors
- Operating System: Raspbian 12 Bookworm (X64)
- Location: Freiston, Lincolnshire, UK
- Contact:
Re: Format of Month
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
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
- steve
- Cumulus Author
- Posts: 26672
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: Format of Month
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.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.
Steve
-
Big Daddy
- Posts: 270
- Joined: Tue 10 Sep 2013 8:40 pm
- Weather Station: Ecowitt GW1000 / various sensors
- Operating System: Raspbian 12 Bookworm (X64)
- Location: Freiston, Lincolnshire, UK
- Contact:
Re: Format of Month
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
Many Thanks
Andy