I am trying to show only the year from a date field for my loop, but when I am trying to call it, it shows me the wrong year. It shows 1970 for all the results.
I'm new to wordpress and php and don't know how to exactly show my results. Is my query for $mydate
incorrect or is it a coding error when being echoed?
<table class="teachpress_publication_list">
<?php
global $wpdb;
// QUERY HERE TO COUNT TOTAL RECORDS FOR PAGINATION
$total = $wpdb->get_var("SELECT COUNT(*) FROM (SELECT * FROM wpfs_teachpress_pub LIMIT 0,650) AS a");
$post_per_page = 10;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$offset = ( $page * $post_per_page ) - $post_per_page;
$result = $wpdb->get_results( "SELECT * FROM wpfs_teachpress_pub ORDER BY date DESC LIMIT $post_per_page OFFSET $offset");
$mydate = $wpdb->get_results( "SELECT date FROM wpfs_teachpress_pub" );
foreach ( $result as $print ) { ?>
<tr class="tp_publication">
<td class="tp_pub_info"> <p class="tp_pub_author"> <?php echo $print->editor; ?><br/>
<span class="tp_pub_title"> <?php echo $print->title; ?></span><br/><?php echo $print->journal; ?> <span class="dd">Year Published:<?php echo date("Y", strtotime($mydate)); ?></span> </p>
</tr>
<?php }
?>
</table>
I expect the output to show the correct year in the date column of MySql db instead of always 1970.
Any help would be greatly appreciated.