Formating the display of a post’s date, outside the Loop
I’m using something like this: date(‘F, Y’, strtotime($data[0]->post_date));
I’m using something like this: date(‘F, Y’, strtotime($data[0]->post_date));
Do you have issue with exactly converting or retrieval? Converting is trivial and is plain PHP: date(‘F j, Y’, strtotime($date)); For more complex and WordPress-specific way with localization support see date_i18n() function.
You use a lowercase y for a 2 digit year. For example (l, F j, Y) –> returns, Friday, September 24, 2004 and (l, F j, y) —> returns Friday, September 24, 04
Use the_time or get_the_time, which accept the same format parameters as php’s date. // assign to a variable $iso8601_date = get_the_time(‘c’); // or output directly the_time(‘c’); EDIT- converting formats with php: $date = “September 11, 2011 9:00 am”; $time = strtotime( $date ); echo date( ‘c’, $time );
Here’s what I use: function oenology_copyright() { global $wpdb; $copyright_dates = $wpdb->get_results(” SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status=”publish” “); $output=””; if($copyright_dates) { $copyright = “© ” . $copyright_dates[0]->firstdate; if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) { $copyright .= ‘-‘ . $copyright_dates[0]->lastdate; } $output = $copyright; } return $output; } Of course, if there’s a … Read more
Here’s what I found which I’ll break up into pieces: for ($i = 1; $i <= 12; $i++) { $month = date(“n”, strtotime( date( ‘Y-m-01’ ).” -$i months”)); $year = date(“Y”, strtotime( date( ‘Y-m-01’ ).” -$i months”)); The for loop will loop through how many months we want to pull, which in this case is … Read more
You can use strtotime() to convert the time to an integer, and then do a conditional. // Get the current time $now = strtotime(“now”); // Convert post’s modification time to int $postUpdated = strtotime( $post->post_modified ); // Check if 3 hours has passed, each hour is 60*60 seconds if ( $now – $postUpdated >= 3*60*60 … Read more
Found this. Modified a bit to offset in hours, and it sorta works, not totally though… does weird stuff with the time if it’s close to midnight. Original here function cc_time_machine( $formatted, $format ) { $offset = -3; // Offset in hours, can be negative. if ( $offset ) { global $post; $timestamp = get_post_time( … Read more
You’re on WordPress.com, so there’s no way to add functionality that will allow you to do this. You could always type the date/time manually whenever you update it.
PHP has a built-in date() function that formats Date-objects. In your case, you would use it as follows: echo date(‘Y’, 1322697600); Since you’re using these query arguments to build up an array of posts, and you want to filter specifically on that, I’d recommend building a function that triggers the loop based on your desired … Read more