Okay, so I have a custom date field set up as 'm/d/Y H:i:s' and I'd like to echo that as 'M j'. How do I do this?
if it stored in the format m/d/Y H:i:s, then you can do this wherever the date is echoed in your template:
echo date('M j',strtotime($custom_date));
Related
I am using the jQuery Date Picker of WordPress ACF Plugin to make a custom Meta Box of a custom POST.
Now, when this Date Picker value is saved to the database table called xxx_postmeta I see that value is:
20190630
So then when I get that meta value using below code:
<?php echo date('F j, Y ', get_post_meta( get_the_ID(), 'article_1_pub_date', true)) ; ?>
then the date is showing wrong, Like this:
August 22, 1970
Is there any wrong or ACF issue?
I assume the date you saved is June 30, 2019. You can’t use PHP date() function on this string.
Convert to a date object and print:
$date = DateTime::createFromFormat('Ymd', '20190630');
echo $date->format('F j, Y ');
I'm developing a website in WordPress with WooCommerce. I am using Woocommerce Subscription. I have a product with a trial period. Now I want to change the next payment date based on the trial period. How can I get the trial period date and Next payment date? So that I can change the Second payment date. I tried using the below-mentioned code but didn't find any solution.
<?php if (has_woocommerce_subscription('','','active') && WC_Subscriptions_Product::get_trial_length( $product_id ) > 10) {
$trial_end = WC_Subscription::get_date( 'trial_end');
echo $trial_end;
}
?>
<?php WC_Subscription::get_date( $date_type, $timezone ) ?>
$date_type
(string) (required) The type of date to get, can be 'start', 'trial_end', 'next_payment', 'last_payment' or 'end'. Default: None
$timezone
(string) (optional) The timezone to use for the returned date, either ‘gmt’ or ‘site’. Default ‘gmt’.
You will get complete document here.
https://docs.woocommerce.com/document/subscriptions/develop/functions/
Update :
$product = wc_get_product($product_id);
$period = WC_Subscriptions_Product::get_period($product);
var_dump($product);
Add output here in question. You will find start and end date as well as next payment date.
The current code below returns my current local time in wordpress and the result looks like this. 2013-07-29 13:45:42
I need to convert this to a timestamp format. What is the answer please?
echo date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) );
The PHP strtotime() function might work.
$timestamp = strtotime('2013-07-29 13:45:42');
EDIT
Here is your use case
$current_date = date('Y-m-d H:i:s'); ## Get current date
$timestamp = strtotime($current_date); ## Get timestamp of current date
echo $timestamp; ## Print timestamp
Come to find out I really just needed the actual date and not a timestamp to achieve my goal. So using this gives you wordpress current local time that is set on the settings page in the admin panel.
date_i18n('Y-m-d');
I'd like to format a datetime entry stored in a SQL db in a friendly format.
I'm just returning a simple query as a row(date)...
Is there a quick/easy way to do this?
I can post examples, if need be.
Right now the query is in a foreach loop:
<?php print $row['exp_date']?>
You can always use the php date function
Day of the week:
echo date("l", strtotime($row['exp_date'])); // monday
More complex sample:
echo date("l jS \of F Y h:i:s A", strtotime($row['exp_date'])); // Monday 8th of August 2005 03:12:46 PM
I'm modifying the Recent-Changes WordPress plugin to display dates. I can echo the date but can't format it; e.g., mm/dd/yyyy.
I'd like the post_modified date to be in mm/dd/yyyy.
I've tried--
echo '<li>'.$RecentChange->post_modified('m/d/Y').
-- but that caused the plugin to stop displaying posts, and generally broke the site.
Below is the relevant chunk from the plugin--
/* define full SQL request */
$rc_sql = "SELECT post_date, post_modified, post_title, ID FROM wp_posts WHERE ".$rc_content_sql." ORDER BY post_modified DESC LIMIT ".$rc_number;
global $wpdb;
echo $before_widget;
echo $before_title.$rc_title.$after_title.'<ul>';
$RecentChanges = $wpdb->get_results($rc_sql);
if ($RecentChanges)
foreach ($RecentChanges as $RecentChange) :
$rc_url = get_page_link($RecentChange->ID);
echo '<li>'.$RecentChange->post_modified.' <a href='.$rc_url.'>'.$RecentChange->post_title.'</a></li>';
endforeach;
echo '</ul>'.$after_widget;
$wpdb->flush();
}
Try
<?php
mysql2date('m/d/Y', $RecentChange->post_modified);
?>
See reference.
Assuming RecentChanges->post_modified is a PHP date or time, you could wrap it in PHP's date function and format it how you want.
date("m/d/Y", $RecentChanges->post_modified);
So, your line would look like this:
echo '<li>'.date("m/d/Y", $RecentChanges->post_modified).' <a href='.$rc_url.'>'.$RecentChange->post_title.'</a></li>';
It's likely that your code is breaking WordPress because the post_modified function is just a getter and doesn't take parameters.