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
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 new to coding in asp.net and I'm struggling to format the date I've managed to pull from our CRM content pages' live date. I've wrote the following code that manages to pull and display the date the page was created:
TheDate = DR["LiveDate"].ToString();
But it formats the date and time like this:
13/11/2012 00:00:00
How can I modify my above code to just display the date like so:
Tuesday, 13 November 2012
Or, just without the time
13/11/2012
Thanks,
I assume that DR is a DataRow, isn't it?
If DR["LiveDate"] is already a DateTime column don't convert it to a localized string via ToString. Just cast it accordingly, for example via Field extension method:
DateTime dt = DR.Field<DateTime>("LiveDate");
If it's not a DateTime but a string you have to parse it to DateTime:
DateTime dt = DateTime.Parse(DR.Field<String>("LiveDate"));
If you want Tuesday, 13 November 2012 as result use:
string result = dt.ToString("dddd, dd MMMM yyyy", CultureInfo.InvariantCulture);
If you want 13/11/2012 use:
string result = dt.ToShortDateString();
or
string result = dt.ToString("d");
if your culture uses / as separator
otherwise
string result = dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
Further informations: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
for your second question, try
TheDate = DR["LiveDate"].ToString("dd/MM/yyyy")
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');
Is there any way to use SOQL to strip the time out of a datetime column or to construct a date?
e.g. SELECT DATE('2001-12-31') would return December 31, 2001
In some kind, you can do this, i.e.,
User a = [Select createddate from user limit 1];
system.debug(a.createddate);
system.debug(a.createddate.format('MM/dd, yyyy ') );
in the debug log, got
|DEBUG|2010-12-13 00:41:39
|USER_DEBUG|[3]|DEBUG|12/13, 2010
It seems can't transfer 12 to December directly.
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));