To show the most current date on your website, you just need to install this great simple script I came across at:

http://rainbow.arch.scriptmania.com/scripts/currentdate.html

The script to use is below:

<!–Place this script anywhere in a page.–> <!–NOTE: You do not need to modify this script.–>


[note]<SCRIPT language=”JavaScript” type=”text/javascript”> <!– // current date – from http://rainbow.arch.scriptmania.com/scripts // Array of day names var dayNames = new Array(“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”); var monthNames = new Array(“January”,”February”,”March”,”April”,”May”,”June”,”July”, “August”,”September”,”October”,”November”,”December”); var dt = new Date(); var y  = dt.getYear(); // Y2K compliant if (y < 1000) y +=1900; document.write(dayNames[dt.getDay()] + “, ” + monthNames[dt.getMonth()] + ” ” + dt.getDate() + “, ” + y); // –> </SCRIPT> [/note]

 


 

You can install the code where ever you want the date to show.  In the screenshot below, the date is showing in the site sidebar, so I installed the script in the WordPress file – sidebar.php.  As mentioned, you can place it anywhere you want though, such as the header.php, footer.php. or other file.  You may need to play around with the placement of the code a bit until it appears exactly where you want it show.

The most important thing to consider is your timezone. If you install the date script and you don’t live in the same timezone as your hosting provider, your current date will most likely reflect that of the hosts timezone, given you use a shared server and not a dedicated server. To make sure your website is reflecting an accurate timezone you may need to add a small piece of code to your php.inifile, found in the root of your web host directory of the website.  The example below is for the east coast timezone.

 

date.timezone = “America/New_York”;

To figure out what timezone code you need for your site, go to http://php.net/timezones and select a city that is in listed and in your area. If you don’t see a php.ini file in your root directory (not every site has one), you can create one by going to notepad, naming it php.ini and of course putting the date.timezone line of code above inside the ini file.  Once you’ve created your ini file, save it and upload it to your host’s root directory.  Life should be good and you should be able to show your visitors the accurate date now.

Still can’t see the correct date after following these steps? 

Some hosting companies offer a default php.ini file you can install in a click, so if you see you’re having a problem with your current date displaying properly, delete your self-made php.ini and install your host’s default file. I recently ran into a problem where everything was setup properly, but the timezone was still pulling from my host out in Utah. Since my client is on the east coast this needed to be corrected. After a couple hours of troubleshooting, I fixed the problem by using the hosts default php.ini file. If you want to center or bold the current date, just use the code below to achieve that look: <!–Place this script anywhere in a page.–> <!–NOTE: You do not need to modify this script.–>

 


 

[note]<center><b><SCRIPT language=”JavaScript” type=”text/javascript”> <!– // current date – from http://rainbow.arch.scriptmania.com/scripts // Array of day names var dayNames = new Array(“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”); var monthNames = new Array(“January”,”February”,”March”,”April”,”May”,”June”,”July”, “August”,”September”,”October”,”November”,”December”); var dt = new Date(); var y = dt.getYear(); // Y2K compliant if (y < 1000) y +=1900; document.write(dayNames[dt.getDay()] + “, ” + monthNames[dt.getMonth()] + ” ” + dt.getDate() + “, ” + y); // –> </SCRIPT></center></b> [/note]

 


 

Hope this information helps someone who’s trying to setup or figure out how to fix a current date timezone issue on their own WordPress website… Share