MyBB Community Forums

Full Version: Date and Time Coding - What Is The Correct Way?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Disclaimer: I am NOT a coder, therefore, I do not know the proper coding words/phrases to make this work.

Here's a screenshot of what I have done with this little part.

I got this from this code:

{$lang->welcome_current_time}

[Image: d30b495ab3682b1b124ca48c88caa9f7.png]

I put this in the index template.

However, I want to separate the time and the date into 2 separate lines.

Something like this:

Current time: xx:xx am/pm
Current date: xx-xx-xx

I want to make it that it shows the USER'S time and date, not from the website (local) time.
If the date is done in user's date format, then I will not need the disclaimer of 'Date is in Month-Day-Year (USA) format'. 

What is the proper code to accomplish this?
Can anyone assist me in getting the correct code for this?
Yes, I can assist you.

For starters, the code {$lang->welcome_current_time}

tells you 2 things here

#1 is... {$lang-
this tells you that what you want to edit is found in the language files.

#2 is.... welcome_current_time
this tells you what language to edit.


so if you look in your language files and find welcome_current_time
then you can add a <br /> or a div class and the text that you want to add.

Let me know how it goes.
(2018-10-05, 01:45 AM)Michael2014 Wrote: [ -> ]Yes, I can assist you.

For starters, the code {$lang->welcome_current_time}

tells you 2 things here

#1 is... {$lang-
this tells you that what you want to edit is found in the language files.

#2 is.... welcome_current_time
this tells you what language to edit.


so if you look in your language files and find welcome_current_time
then you can add a <br /> or a div class and the text that you want to add.

Let me know how it goes.

No, that is not what I want.

I will wait for others to respond to this thread.
// Set the current date and time now
$datenow = my_date($mybb->settings['dateformat'], TIME_NOW, '', false);
$timenow = my_date($mybb->settings['timeformat'], TIME_NOW);
$lang->welcome_current_time = $lang->sprintf($lang->welcome_current_time, $datenow . $lang->comma . $timenow);

$datenow and $timenow put together the current time, so you’ll just use those variables in the manner of which you’d like to display them.

Current Date: {$datenow}
<br/>
Current Time: {$timenow}

HOWEVER this uses the PHP format of date and time set in the ACP, so the user will input their timezone via the user cp but the formatting comes from how it is set up via settings. Smile
(2018-10-05, 06:14 PM)isoldehn Wrote: [ -> ]
// Set the current date and time now
$datenow = my_date($mybb->settings['dateformat'], TIME_NOW, '', false);
$timenow = my_date($mybb->settings['timeformat'], TIME_NOW);
$lang->welcome_current_time = $lang->sprintf($lang->welcome_current_time, $datenow . $lang->comma . $timenow);

$datenow and $timenow put together the current time, so you’ll just use those variables in the manner of which you’d like to display them.

Current Date: {$datenow}
<br/>
Current Time: {$timenow}

HOWEVER this uses the PHP format of date and time set in the ACP, so the user will input their timezone via the user cp but the formatting comes from how it is set up via settings. Smile

The bottom code is what I needed!

I was able to fix the code in my new theme INDEX template and now it looks like this...

[Image: f3ffbd2af45b9d713f7f5e3ce708b411.png]