Time element is printing the date as well (drupal 9 webform) - drupal

I am trying to print out the submitted data of a time element selected by the user in twig.
{{ (webform_token('[webform_submission:values:time]', webform_submission))|date('h:i A', 'UTC') }}
This line of code would print Tue, 05/24/2022 - 08:45 while the time element provides
I would only like to print the time, 8:45. How should I do so?
Thank you in advance

Related

Tabulator Cell datetime object - Need to Format

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>

How to customize `serverTimestamp()`?

I want to customise setTimestamp().
firebase.firestore.FieldValue.serverTimestamp()
Currently the output is like August 27, 2019 at 3:38:55 PM UTC+5:30. What to do if I want the result to be August 27, 2019 only ?
When a timestamp type field is written to Cloud Firestore, it is just storing a value that describes a moment in time that's the same for all people on earth. What you're seeing in the console is just format that the console is using to make that readable by people. The timezone is represented in your computer's configured timezone.
If you're reading that timestamp in your code and want to format it for display in your app, you'll need to use some date formatting library to make that easy. It looks like you might be using JavaScript, so consider using a library such as momentjs to help with that. You will likely have to convert the timestamp to a Date type object first.
Firebase will always set a timestamp in a consistent way.
A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time.
As the output you have given has a timezone, I'm guessing this has been applied elsewhere in your code when generating a Date object.
With this date object it is easy enough to reformat to match your desired display. An easy way if you are using angular is to use the date pipe
{{ dateObj | date }} // output is 'Jun 15, 2015'
{{ dateObj | date:'medium' }} // output is 'Jun 15, 2015, 9:43:11 PM'
{{ dateObj | date:'shortTime' }} // output is '9:43 PM'
{{ dateObj | date:'mm:ss' }} // output is '43:11'
In your template you can call .toDate() method of your timestamp field. Do something like:
{{response.data().updatedAt.toDate() | date}}
The date pipe supports multiple formats:
{{response.data().updatedAt.toDate() | date:'short'}}
{{response.data().updatedAt.toDate() | date:'long'}}
...
See datePipe documentation.

How to add a specific number of days (+1 day) to current date in (ISO & RFC format) for "WordPress"?

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 :)

report builder 3.0 date timestamp expression

I have a report that uses the folowing expression in a date timestamp field to format the date as either US format or European format depending on a Language prompt the user selects:
=iif(Parameters!LANG.Value = "EN", ToDateTime(Fields!TRANS_DATE.Value).ToString("MM/dd/yyyy"), ToDateTime(Fields!TRANS_DATE.Value).ToString("dd-MM-yyyy"))
If he user selects English, April 1st appears as 04/01/16. If they select any other format, the date appears as 01-04-16. Works great.
I would like to do the same thing on another field but I would like to leave the time in the results. So, if the user selects English, the results would display 04-01-16 11:15:23 AM. Otherwise, I would like to see 01-04-16 11:15:23 AM.
Can I modify the expression above to do the same thing but leave the hours and minutes and seconds in the result?
Thanks for your help.......
You need to append this to your datetime format string:
"hh:mm:ss tt"
So in your case:
=iif(Parameters!LANG.Value = "EN", ToDateTime(Fields!TRANS_DATE.Value).ToString("MM/dd/yyyy hh:mm:ss tt"), ToDateTime(Fields!TRANS_DATE.Value).ToString("dd-MM-yyyy hh:mm:ss tt"))

drupal7 change format of comment's $created

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.

Resources