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

Date format for $mrecordhighgustday?

Discussion of Ken True's web site templates

Moderator: saratogaWX

Post Reply
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Date format for $mrecordhighgustday?

Post by William Grimsley »

Hi Ken,

I currently have this code in my ajax-dashboard.php file but I'm confused on how to change the day number in the date from 1 to 01 e.g. 1 Feb to 01/02?

Code: Select all

<?php if(isset($mrecordwindgust)) { ?>
              <tr>
                <td colspan="2" class="data1" align="center">
				  <?php langtrans('Month'); ?>: <?php echo $mrecordwindgust. " $uomWind"; ?> 
                  <?php if(isset($mrecordhighgustday)) { ?>
				  <?php echo date("d/m"); ?>
                  <?php } // $mrecordhighgustday ?>
				</td>
              </tr>
              <?php } // $mrecordwindgust ?>
As you can see I have put <?php echo date("d/m"); ?> for the day/month field but my question is, is that code showing the current date in that date format or is it showing the record date in that date format?

Sorry to bother you again,

William
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Date format for $mrecordhighgustday?

Post by saratogaWX »

Will,
These are the kind of questions you can answer for yourself by just looking at where the data comes from and how it arrives at the variable in question.

Cumulus PHP data arrives via CUtags.php and is converted to $variables by CU-defs.php

Looking at http://www.newton-poppleford-weather.co ... p?sce=view shows

Code: Select all

$mrecordwindgust = $WX['MonthGustH'];
list($mrecordhighgustday,$mrecordhighgustmonth,$mrecordhighgustyear)=CU_getRecordDate($WX['MonthGustHD'],$WX['year']); // calculated value
So there are three variables already made containing the day, month, year values for display.

Your code of

Code: Select all

<?php if(isset($mrecordhighgustday)) { ?>
              <?php echo date("d/m"); ?>
                  <?php } // $mrecordhighgustday ?>
will only display the current day/month .. not the data you desire.

I suggest

Code: Select all

<?php if(isset($mrecordhighgustday)) { ?>
              <?php echo "$mrecordhighgustday/$mrecordhighgustmonth"; ?>
                  <?php } // $mrecordhighgustday ?>
which should display the data you seek.
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: Date format for $mrecordhighgustday?

Post by William Grimsley »

Hi Ken,

Yes, I looked in the CU-defs.php...

Well, the Month: gust shows 1/2 not 01/02... :(

William
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Date format for $mrecordhighgustday?

Post by saratogaWX »

That seems overly fussy to me (complaining about the lack of leading zeroes).

If it really annoys you, try using

Code: Select all

<?php echo $mrecordhighgustday . '/' .$mrecordhighgustmonth; ?>
and see if that uses the native values in the variables instead of just processing their values as numbers in the " " display.
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: Date format for $mrecordhighgustday?

Post by William Grimsley »

Hi Ken,

No, that didn't work. :(

Sorry, I'm not trying to be fussy or annoy you.

Ok, but how come the date in the ajax-dashboard.php is like this: 01/02/2012...

William
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Date format for $mrecordhighgustday?

Post by saratogaWX »

So the variables contain numbers, not strings. Force it to print as you like with

Code: Select all

<?php printf('%02d/%02d',$mrecordhighgustday ,$mrecordhighgustmonth); ?>
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: Date format for $mrecordhighgustday?

Post by William Grimsley »

Hi Ken,

Thanks very much, that worked! I was nearly on it last night but it was getting so late I just couldn't figure it out. :lol:

So putting

Code: Select all

%02d
into some PHP code will put a 0 in front of the number? Interesting...I WILL use that code IF a similar problem pops up again! :D

Thanks again,

William
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Date format for $mrecordhighgustday?

Post by saratogaWX »

Not quite correct .. the %02d is a format specifier for use with the builtin functions of printf() and sprintf() .. it is not used elsewhere.

See: http://www.php.net/manual/en/function.sprintf.php and http://www.php.net/manual/en/function.printf.php

The format code documentation is included in the sprintf() doc.

The printf() function does the format and prints the result, sprintf() does the format and returns the resulting string.
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: Date format for $mrecordhighgustday?

Post by William Grimsley »

saratogaWX wrote:Not quite correct .. the %02d is a format specifier for use with the builtin functions of printf() and sprintf() .. it is not used elsewhere.

See: http://www.php.net/manual/en/function.sprintf.php and http://www.php.net/manual/en/function.printf.php

The format code documentation is included in the sprintf() doc.

The printf() function does the format and prints the result, sprintf() does the format and returns the resulting string.
Hi Ken,

Oh, right! So does the %02d code do something else?

Thanks for the links! I will take a look at them soon! :D

Thanks

William
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Date format for $mrecordhighgustday?

Post by saratogaWX »

William Grimsley wrote:
saratogaWX wrote:the %02d is a format specifier for use with the builtin functions of printf() and sprintf() .. it is not used elsewhere.
Hi Ken,

Oh, right! So does the %02d code do something else?
Will, (no reply is necessary)

You should know that your response 'So does the %02d code do something else?' just indicates that you did not read and understand what I said. Please avoid quick replies that have no meaning other than to indicate you didn't comprehend.
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: Date format for $mrecordhighgustday?

Post by William Grimsley »

Oh, sorry. I won't do that again. :oops:
Post Reply