May 19, 2013

Use getdate() to Add Current Date to WordPress Site

If you’ve ever wondered about a quick way to add the current date to your wordpress site you can easily do it using the getdate() and date() functions that are built in with php.

First you’ll want to get the date and put it into an array, in this case, $useable_time.

<?php
$useable_time=getdate(date(“U”, strtotime(‘-10 hours’)));
?>

You’ll want to adjust the ‘-10 hours’ portion of this to match whatever timezone you’re posting from off of GMT.  getdate() then saves the date as an array that you can call and display as you wish.  See all of the date return values in the php manual.

You can create a date like “Monday, January 18, 2011″ by printing the array like this.

print(“$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]“);