Changing Month from a number to name

Get help with installation and running phpBB 3.2.x here. Please do not post bug reports, feature requests, or extension related questions here.
Post Reply
User avatar
Webmaster Chuck
Registered User
Posts: 26
Joined: Thu Feb 25, 2016 10:21 pm
Location: Glendale, AZ
Name: Charles Waters
Contact:

Changing Month from a number to name

Post by Webmaster Chuck » Sun May 12, 2019 9:57 pm

Good afternoon everyone.

I was wondering if someone could tell me in what file I can find where the months are located?

I would like to change them from a number, to the actual name of the month.

And, if this will pose a problem anywhere else?

Thank you!

User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 50356
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Changing Month from a number to name

Post by stevemaury » Sun May 12, 2019 10:12 pm

That is controlled by the php DATE function, which you can set for Guests in Board settings and for yourself in the User control panel. Capital 'F' is what you want. See https://www.php.net/manual/en/function.date.php
For REALLY good and VERY inexpensive hosting CLICK HERE

I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)

User avatar
Webmaster Chuck
Registered User
Posts: 26
Joined: Thu Feb 25, 2016 10:21 pm
Location: Glendale, AZ
Name: Charles Waters
Contact:

Re: Changing Month from a number to name

Post by Webmaster Chuck » Tue May 14, 2019 5:39 am

stevemaury wrote:
Sun May 12, 2019 10:12 pm
That is controlled by the php DATE function, which you can set for Guests in Board settings and for yourself in the User control panel. Capital 'F' is what you want. See https://www.php.net/manual/en/function.date.php
Good evening, and thank you for the reply.

I currently have my date set up as "|l F jS, Y| - g:i a".

Are you talking about setting it somewhere else other than that?

User avatar
EA117
Registered User
Posts: 533
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Changing Month from a number to name

Post by EA117 » Tue May 14, 2019 5:49 am

Webmaster Chuck wrote:
Tue May 14, 2019 5:39 am
I currently have my date set up as "|l F jS, Y| - g:i a".
And you are saying this does or does not already achieve your goal, by displaying a full name of the month where the "F" is positioned within that date format string?

If this is what your date format is already set to, but you're still seeing a scenario where "I need to display the month as a name instead of a number", perhaps we need to see a screen shot that confirms exactly what you're seeing & where.

User avatar
Webmaster Chuck
Registered User
Posts: 26
Joined: Thu Feb 25, 2016 10:21 pm
Location: Glendale, AZ
Name: Charles Waters
Contact:

Re: Changing Month from a number to name

Post by Webmaster Chuck » Wed May 15, 2019 4:48 pm

EA117 wrote:
Tue May 14, 2019 5:49 am
Webmaster Chuck wrote:
Tue May 14, 2019 5:39 am
I currently have my date set up as "|l F jS, Y| - g:i a".
And you are saying this does or does not already achieve your goal, by displaying a full name of the month where the "F" is positioned within that date format string?

If this is what your date format is already set to, but you're still seeing a scenario where "I need to display the month as a name instead of a number", perhaps we need to see a screen shot that confirms exactly what you're seeing & where.
Good morning. I was talking screenshots earlier this morning to post on here..

So, as you can see in the first pic, My date format shows the way I want it:
correcttime.png
This is the correct showing of the way the date / time should be.
And this one, when someone selects their birthday, it doesn't show the month in the words, simply the month number:
incorrectmonth.png
This is incorrect when selecting a birthday.
incorrectmonth.png (7.16 KiB) Viewed 286 times

User avatar
Lumpy Burgertushie
Registered User
Posts: 66147
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Changing Month from a number to name

Post by Lumpy Burgertushie » Wed May 15, 2019 5:05 pm

that is a whole other thing. I believe it will require an extension to be written.


robert
I am available for custom work on a donation basis. Please send me a PM with your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

OK, so what's the speed of dark?

User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 50356
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Changing Month from a number to name

Post by stevemaury » Wed May 15, 2019 7:33 pm

AFAIK, the actual birthdate is never displayed anyway. There is only a listing of "Birthdays" on the index page, and an "Age" in the profile. Where are you seeing the birthdates listed? If they aren't displayed, it hardly matters whether the month is spelled out.
For REALLY good and VERY inexpensive hosting CLICK HERE

I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)

User avatar
EA117
Registered User
Posts: 533
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Changing Month from a number to name

Post by EA117 » Wed May 15, 2019 8:38 pm

stevemaury wrote:
Wed May 15, 2019 7:33 pm
If they aren't displayed, it hardly matters whether the month is spelled out.
It mattered enough to come here and ask. It's being displayed right where he's showing the screen shot: On the input form.

i.e. We're talking about the issue of military time being less familiar to some than standard time, and numeric months being less intuitive than verbose month names, time zone offsets being less familiar than time zone names, etc. The requested change makes it easier for users to input their birthday, by making the month selection more intuitive.
Webmaster Chuck wrote:
Wed May 15, 2019 4:48 pm
And this one, when someone selects their birthday, it doesn't show the month in the words, simply the month number:
Agreed, this isn't an invocation of "please display this current or posting date in the user's selected format." This selection dialog, and the fact each date component is separately selectable, is uniquely constructed just for the birthday input. Neither the user's date format selection nor the board date format selection will affect this birthday input form.

If you were looking for a simple "there is a place where there is a number and I can change that to a name", its not going to be that straight forward. So if you weren't looking for complexity, perhaps consider to stop reading now and move on.


But you should be able to achieve a fixed single-language solution through modifying the style templates alone, by adding some JavaScript to the page which will modify the display string used in the HTML form <option> fields from the numeric representation to the verbose representation. The templates in question are the templates where you find {S_BIRTHDAY_MONTH_OPTIONS} being referenced, which are ucp_profile_profile_info.html and acp_users_profile.html.

That {S_BIRTHDAY_MONTH_OPTIONS} variable literally contains just the list of HTML "<option value=1>1</option>", "<option value=2>2</option>", etc., input selections for the month. You could almost get away with simply replacing the {S_BIRTHDAY_MONTH_OPTIONS} reference with your own set of literal HTML <option> fields directly as part of the template; but doing that would lose track of which month is currently selected, when a user is viewing the birthday they already entered in their profile. So that is why JavaScript to manipulate the HTML input form that phpBB already built is necessary, because the <options> list phpBB built has the proper "selected" attribute set.

The reason I say "single language" is because I don't believe the phpBB translated month names are available to the template itself. (e.g. {L_JANUARY}, {L_FEBRUARY}, etc.) If someone knows I'm wrong and the template can already refer to the translated month names without PHP code changes, please let Webmaster Chuck know, because that would allow the JavaScript to replace the month names using translated references.

Edit:
Its up to you to work out whether taking the template & JavaScript approach is what you want to do. It should definitely be possible to achieve what you want without involving an extension or PHP code changes, but the changes are non-trivial enough that I didn't take time to work them all out.

It finally dawned on me that the JavaScript for the template change didn't need to be as complicated as I was assuming. I expected to have to wait until the form was built, then locate and update the form input options in the DOM with code such as "document.form['birthday'].input['month'].options[1].innerHtml = 'January'" or similar. But it came to mind that we could instead just use JavaScript to manipulate the {S_BIRTHDAY_MONTH_OPTIONS} contents before they are used.

Meaning for example in the ucp_profile_profile_info.html template, replace the following line:

Code: Select all

				<label for="bday_month">{L_MONTH}{L_COLON} <select name="bday_month" id="bday_month">{S_BIRTHDAY_MONTH_OPTIONS}</select></label>
With a block such as:

Code: Select all

                <label for="bday_month">{L_MONTH}{L_COLON} <select name="bday_month" id="bday_month">
                <!-- IF S_USER_LANG eq 'en-gb' -->
                <script>
                    var verbose_date_selection = '{S_BIRTHDAY_MONTH_OPTIONS}';
                    verbose_date_selection = verbose_date_selection.replace('>1<', '>January<');
                    verbose_date_selection = verbose_date_selection.replace('>2<', '>February<');
                    verbose_date_selection = verbose_date_selection.replace('>3<', '>March<');
                    verbose_date_selection = verbose_date_selection.replace('>4<', '>April<');
                    verbose_date_selection = verbose_date_selection.replace('>5<', '>May<');
                    verbose_date_selection = verbose_date_selection.replace('>6<', '>June<');
                    verbose_date_selection = verbose_date_selection.replace('>7<', '>July<');
                    verbose_date_selection = verbose_date_selection.replace('>8<', '>August<');
                    verbose_date_selection = verbose_date_selection.replace('>9<', '>September<');
                    verbose_date_selection = verbose_date_selection.replace('>10<', '>October<');
                    verbose_date_selection = verbose_date_selection.replace('>11<', '>November<');
                    verbose_date_selection = verbose_date_selection.replace('>12<', '>December<');
                    document.write(verbose_date_selection);
                </script>
                <!-- ELSE -->
                {S_BIRTHDAY_MONTH_OPTIONS}
                <!-- ENDIF -->
                </select></label>
Such that we're letting standard phpBB code build the <options> list (including the "selected" attribute we want), but then simply replace the display numbers with display names in the composed <options> list, before that list gets emitted to the HTML document. Also included is an explicit test for "en-gb" language, and we let other languages simply display the numbers.

No, I do not expect this causes any future data problems for phpBB, because all we're changing is the HTML display string. The value when a given month is selected is still the numeric month, and the numeric value will still be what gets POSTed back to phpBB when the form is submitted. So from phpBB's perspective, "there hasn't been any change" in the data received or stored for the month. You're only changing how the selection was displayed in HTML.


If multi-language support is a requirement, to achieve a proper language-aware implementation means you need to change the PHP code that builds the S_BIRTHDAY_MONTH_OPTIONS value. Meaning as Robert said, it would require an extension that overrides the S_BIRTHDAY_MONTH_OPTIONS template variable on these pages. Or, to do it without an extension, it would require editing the core phpBB files, which creates long-term maintenance for you to keep the fix in place.

Without an extension, it would be a matter of updating the code you see building the $s_birthday_month_options value in /includes/ucp/ucp_profile.php and /includes/acp/acp_users.php, with something like my quick and un-sexy example here:

Code: Select all

					$s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
					for ($i = 1; $i < 13; $i++)
					{
						$verbose_month = 'Unknown';

						switch ($i)
						{
							case 1:
								$verbose_month = $user->lang['datetime']['January'];
								break;
							case 2:
								$verbose_month = $user->lang['datetime']['February'];
								break;
							case 3:
								$verbose_month = $user->lang['datetime']['March'];
								break;
							case 4;
								$verbose_month = $user->lang['datetime']['April'];
								break;
							case 5:
								$verbose_month = $user->lang['datetime']['May'];
								break;
							case 6:
								$verbose_month = $user->lang['datetime']['June'];
								break;
							case 7:
								$verbose_month = $user->lang['datetime']['July'];
								break;
							case 8:
								$verbose_month = $user->lang['datetime']['August'];
								break;
							case 9:
								$verbose_month = $user->lang['datetime']['September'];
								break;
							case 10:
								$verbose_month = $user->lang['datetime']['October'];
								break;
							case 11:
								$verbose_month = $user->lang['datetime']['November'];
								break;
							case 12:
								$verbose_month = $user->lang['datetime']['December'];
								break;
						}

						$selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
						$s_birthday_month_options .= "<option value=\"$i\"$selected>$verbose_month</option>";
					}

User avatar
canonknipser
Registered User
Posts: 1932
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Changing Month from a number to name

Post by canonknipser » Thu May 16, 2019 6:07 pm

EA117 wrote:
Wed May 15, 2019 8:38 pm
is uniquely constructed just for the birthday input.
And it is with intention - because you can put in a date without a year for just showing the birthday, but not the age in the profile.
EA117 wrote:
Wed May 15, 2019 8:38 pm
The requested change makes it easier for users to input their birthday, by making the month selection more intuitive.
That's a personal opinion.
I like it to have input fields where I can type in the numbers - it's much faster than rolling down a selector. It's only 12 values for the month, but 31 for the day and > 100 for the year (which I must roll halfway down to reach my year of birth). Typing in 8 numbers is much faster and in my eyes more intuitive
EA117 wrote:
Wed May 15, 2019 8:38 pm
We're talking about the issue of military time being less familiar to some than standard time,
What's "military time"? Your talking about the 24 hour format? That is standard time, not the 12 hour time format :geek:

But hey - this is about a input method a user uses in most cases only once in his board membership time ...
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB

User avatar
EA117
Registered User
Posts: 533
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Changing Month from a number to name

Post by EA117 » Thu May 16, 2019 6:18 pm

canonknipser wrote:
Thu May 16, 2019 6:07 pm
But hey - this is about a input method a user uses in most cases only once in his board membership time ...
Yep. If there was something in there for how this affects helping OP achieve the requested goal, I missed it.

User avatar
3Di
Former Team Member
Posts: 13603
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Changing Month from a number to name

Post by 3Di » Thu May 16, 2019 8:10 pm

Military time is Zulu Military Time BTW, the same as UTC.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
Webmaster Chuck
Registered User
Posts: 26
Joined: Thu Feb 25, 2016 10:21 pm
Location: Glendale, AZ
Name: Charles Waters
Contact:

Re: Changing Month from a number to name

Post by Webmaster Chuck » Fri May 17, 2019 1:07 am

EA117 wrote:
Wed May 15, 2019 8:38 pm
stevemaury wrote:
Wed May 15, 2019 7:33 pm
If they aren't displayed, it hardly matters whether the month is spelled out.
Meaning for example in the ucp_profile_profile_info.html template, replace the following line:

Code: Select all

				<label for="bday_month">{L_MONTH}{L_COLON} <select name="bday_month" id="bday_month">{S_BIRTHDAY_MONTH_OPTIONS}</select></label>
With a block such as:

Code: Select all

                <label for="bday_month">{L_MONTH}{L_COLON} <select name="bday_month" id="bday_month">
                <!-- IF S_USER_LANG eq 'en-gb' -->
                <script>
                    var verbose_date_selection = '{S_BIRTHDAY_MONTH_OPTIONS}';
                    verbose_date_selection = verbose_date_selection.replace('>1<', '>January<');
                    verbose_date_selection = verbose_date_selection.replace('>2<', '>February<');
                    verbose_date_selection = verbose_date_selection.replace('>3<', '>March<');
                    verbose_date_selection = verbose_date_selection.replace('>4<', '>April<');
                    verbose_date_selection = verbose_date_selection.replace('>5<', '>May<');
                    verbose_date_selection = verbose_date_selection.replace('>6<', '>June<');
                    verbose_date_selection = verbose_date_selection.replace('>7<', '>July<');
                    verbose_date_selection = verbose_date_selection.replace('>8<', '>August<');
                    verbose_date_selection = verbose_date_selection.replace('>9<', '>September<');
                    verbose_date_selection = verbose_date_selection.replace('>10<', '>October<');
                    verbose_date_selection = verbose_date_selection.replace('>11<', '>November<');
                    verbose_date_selection = verbose_date_selection.replace('>12<', '>December<');
                    document.write(verbose_date_selection);
                </script>
                <!-- ELSE -->
                {S_BIRTHDAY_MONTH_OPTIONS}
                <!-- ENDIF -->
                </select></label>
This is EXACTLY what I was looking for. I made this one change in my test environment, logged in, and the UCP for one of my test accounts showed this:
months.png
Correct listing I was looking for.
months.png (9.32 KiB) Viewed 126 times
That is perfect! Thank you!

Now, just to change the display to M/D/Y, instead of D/M/Y.

Thank you all for the input and thoughts.

I'm glad I could actually start a small, simple debate among fellow forumer's!

Post Reply

Return to “[3.2.x] Support Forum”