I have been trying for some time now to reformat the date that appears below the avatar when a comment is made to a blog post.
I have found no way of doing it through any settings, so I have moved over to the template files. Changing the date format of the original blog post was easy, but with comments, no variable holding the date in raw (unix) format is passed in to the template, so I can't reformat and extract the pieces of the date that I want.
The Zen theme help note says:
* - $created: Formatted date and time for when the comment was
created.
I would like to reformat this from
Tue, 2011-09-13 11:57
Into two separate variables,
13 Sep, 2011
11:57
any idéas? Thanks
In your template file you should have access to the $node variable so you can do something like this:
echo date('j M, Y H:i', $node->created);
See the PHP date page for information on the format string used above.
Related
I am attempting to reformat a datetime value in a cell that contains TZ UTC data. An example value is: 2019-12-09T14:50:47.000Z-0500
I need it to display as:
MM/DD/YYYY HH:mm:ssXM - ex: 12/09/2019 02:50:47PM
Local time, of course.
I have tried reading the moment.js doc without success. Here is a snippet I have attempted. The table shows up with "blank rows." If I remove the formatting, the data shows correctly but not with the date and time format I would like.
{title:"Last Submitted", field:"createdOn", sorter:"date", formatter:"datetime", formatterParams:{inputFormat:"YYYY-MM-DD hh:mm:ss", outputFormat:"MM/DD/YYYY", invalidPlaceholder:"(Invalid date)"}},
Any assistance would be greatly appreciated!
Ben
UPDATE BASED ON ANSWER 12/26/2019
Thank you again for responding. However, this is perhaps an issue for the author of Tabulator since I copied the inputFormat and outputFormat verbatim into the column definition of a Tabulator component and it displays blank rows. If I remove the column cell formatter (which is a wrapper around moment.js code), the list displays with the full timestamp (including UTC / zulu time).
ex:
2019-12-09T12:50:47.000Z-0500
Expected result (either 24h or 12h format doesn't matter at this point - and I did try to remove the "A" for the AM/PM indicator)
Unfortunately, I cannot upload the code for this project since it makes internal WS calls for JSON results (which is another issue - Remote Pagination does not appear to be working.)
Here is the source code for the column:
{title:"Last Submitted", field:"createdOn", sorter:"date", formatter:"datetime", formatterParams:{inputFormat:"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]Z", outputFormat:"MM/DD/YYYY HH:mm:ssA",invalidPlaceholder:"(Invalid date)"}},
As stated above, if I add the formatter, blank table appear and nothing else. If I remove the formatter all data is displayed including the unformatted date (well it's formatted in a way in which I nor my users will want).
Any ideas would be greatly appreciated!
Image of Result with datetime formatter
With momentjs you can parse date if you know the format of an input string:
moment(inDate, inFormat);
For example:
moment('12-25-1995', 'MM-DD-YYYY');
In your case format of an input string is YYYY-MM-DD[T]HH:mm:ss.SSS[Z]Z - square brackets work as escape characters.
You can get formatted string from moment object with .format method:
moment().format(outFormat);
For example:
moment().format('MM-DD-YYYY');
In your case format of an output string is MM/DD/YYYY HH:mm:ssA - you can read more in docs
You can see how both parsing and formatting work together in the snippet below:
let inDate = '2019-12-09T14:50:47.000Z-0500',
inFormat = 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]Z',
outFormat = 'MM/DD/YYYY HH:mm:ssA',
outDate = moment(inDate, inFormat).format(outFormat);
console.log(`In Date: ${inDate}`);
console.log(`Out Date: ${outDate}`);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
I have been searching for a long time to find out how easily to add a specific number of days (+1 day) to current date in (ISO & RFC format) for "WordPress"?
Anyway, After tons of testings and failure I came up with the final solution.
Solution:
First of all, We must get the default current post date (get_the_date), Then add the desired format (ISO or RFC), and finally increase it by adding more +days to it as follow:
<?php
$Date = get_the_date('Y-m-d');
echo date('c', strtotime($Date. ' + 10 days'));
?>
The results will be:
- Current date: 2018-09-14
- Increased date: 2018-09-24T00:00:00+00:00 *(with ISO format)*.
This achievement can be useful when you want to validate sitemap, Wordpress feed, or add schema markup to your pages (manually).
Hope this can help you :)
I am trying to obtain a date from an XML file that is in this format:
2016-10-27
however, the field I am trying to put it in is in this format:
mm/dd/yyyy
is there a code for this in dynamics ax 2012? I tried str2date but it doesn't output anything.
SOLVED: Just to let you guys know even though you are obtaining a string that has a format like mine 2016-10-27 AX automatically formats it to the default format to 10/27/2016 just input the sequence correctly. (THIS IS NOT PART OF THE ANSWER I AM JUST EXPLAINING MY FINDINGS)
You will need to use str2date(string _date, int _sequence). Specify the related format in sequence. Your desired format will be 213
So I'm trying to pull the data in a row from a separate sheet (sheet2!), if part of Col A has the the Date that is in sheet1! C1.
Col A ex: "Build 251 at Fri Jun 12 03:03:49 2015"
Col C1 ex: "Fri Jun 12" (Changes date every couple days)
I've tried these formulas but they don't work. The errors I get back are "finished with no results"; "error filter has mismatched range sizes"; "there is no ColumnA"; "formula parse error"
=filter("'GitHub-Changelog'!A", ("'GitHub-Changelog'!A" = 'x64 RSS Data'!C2))
=QUERY('GitHub-Changelog'!A:F,"select * where A contains '(TRANSPOSE(" "&C1:C&" "))'")
=FILTER('GitHub Changelog'!A,MMULT(SEARCH(TRANSPOSE(" "&'x64 RSS Data'!C1:C&" ")," "&'GitHub-Changelog'!A1:A&" "),SIGN(ROW('GitHub-Changelog'!A1:A))))
I'm not sure why I'm not getting results, the date is in A. If I use this =QUERY('GitHub-Changelog'!A:F,"select * where A contains 'Fri Jun 12'") It prints out the single row, it's just not reading C1 for some reason; and I need it to be dynamic to match whatever C1 changes to.
*The true future ideal goal would be to check Sheet1!C against Sheet2!A, if part of A contains C then copy whole row (Sheet2!A:F) into a single cell (Sheet1!E). Along the lines of IF Sheet2!A contains sheet1!C1 then copy (sheet1!E=Sheet2!D&C&B, but I believe that needs full script writing to accomplish this so I'm not sure how to do it yet, but will learn; one thing at a time though (just thought I'd share a better version of what I'm trying to accomplish).
Here is the sheet I'm working on: https://docs.google.com/spreadsheets/d/1lPOwiYGBK0kSJXXU9kaQjG7WNHjnNuxy25WCUudE5sk/edit?usp=sharing. It pulls multiple pages on different sheets, then cleanup pages of the data. The plan is to have an update sheet that searches the changelog info for the date of the current build and puts that data next the build. So the final sheet will show most recent build + commit changes for that nightly build. That's where this function is being used, to scrape the changelog for the same date.
See if this works:
=query('GitHub-Changelog'!A:F; "where A contains '"&C1&"' ")
where C1 (on the same sheet as the formula) is the cell that holds the date (ex: Fri Jun 12).
You don't need to surround the range with "".
Also, you can use Find() in your filter, to check if that date is present in the string.
Here is a working Filter formula:
=FILTER('GitHub-Changelog'!A:F, Find('x64 RSS Data'!C1,'GitHub-Changelog'!A:A))
I came across this chunk of data while going through a theme's metadata in wordpress. It looks like instead of using several metadata keys for different bits of data, they smooshed it all together in one chunk. This in particular is meta data for an event post type:
a:3:{s:8:"dateFrom";s:16:"Mon, 10 Feb 2014";s:6:"dateTo";s:16:"Mon, 10 Feb 2014";s:8:"location";s:87:"Convention Center";}"
I mostly just want to extract "dateFrom" so I can display it in a widget.
It looks like for other events the only things that change are the actual values (dates, location). The parts that are [a-z]:[0-9]* (which seem to be keys, but they aren't valid JSON keys cause of the colons) are constant.
That value is PHP serialized. If you unserialize it it'll be converted to an array. So something like (untested):
$orig = 'a:3:{s:8:"dateFrom";s:16:"Mon, 10 Feb 2014";s:6:"dateTo";s:16:"Mon, 10 Feb 2014";s:8:"location";s:87:"Convention Center";}"';
$converted = unserialize($orig);
echo $converted['dateFrom'];
should do the trick