I have a date coming through as 25/4/2022. I need it changed to 25/APRIL/2022. I have tried every combination of ?date('dd/mm/yyyy') / ?datetime('dd/mmm/yyyy') ?datetime(dd/mm/yyyy)?string('dd/mmm/yyyy') that I can think of but I keep getting teh same type of errors:
The string doesn't match the expected date/time/date-time format.
The nested reason given follows: Unparseable date: "" ---- FTL stack trace ("~" means nesting-related)
What am I missing here?
You need to use a Java SimpleDateFormat pattern to format dates. If you want the month, use M (uppercase), as m (lowercase) is minutes in hour. For a full month, use MMMM. So, use:
${"25/April/2022"?date("dd/MMMM/yyyy")}
See also:
https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_string_date
https://freemarker.apache.org/docs/ref_directive_setting.html#topic.dateTimeFormatSettings
How to parse month full form string using DateFormat in Java?
Related
I have a DateTime variable (default formatting), and I would like to format it to a format to I receive from a string parameter.
I normally do something similar to: {myDate:yyyy-MM-dd}, and it works properly.
Now I have a lot of possible date formats and need to format according to the chosen one.
I have tried the following but returned garbage (ae0aor0aa):
string testFormat = "yyyy. MM. dd.";
{myDate:testFormat }
I have also tried to convert the date to string and back to date with ParseExact, but gave me an invalid date exception. NB: the date in myDate is valid, as I have checked it with the debugger.
Can you kindly advise?
Thanks to apc, it was easily solved by myDate.ToString(testFormat)
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>
In data lake I have file names with pattern yyyyMM_data.csv. Now I want to read previous 3 days data. I am using below code -
DECLARE #ReportDate DateTime= DateTime.Parse("05/08/2017");
DECLARE #FeatureSummaryInput string=#"/FolderPath/{InputFileDate:yyyy}{InputFileDate:MM}_data.csv";
#FeaturedUsed =
EXTRACT Id string,InputFileDate DateTime
FROM #FeatureSummaryInput
USING Extractors.Csv(silent : true, skipFirstNRows : 1);
#FeaturedUsed=
SELECT *
FROM #FeaturedUsed
WHERE InputFileDate BETWEEN #ReportDate.AddDays(-3) AND #ReportDate;
If I run above code it runs with empty input. Please let me know if I am missing something. Why it is not reading correct file?
It seems like we need to must have "day" in file name pattern to work this.
Possibly I am missing something but, as you cast InputFileDate to DateTime it defaults to the first of the month, as no day is specified. For your test ReportDate set to 05/08/2017, your WHERE clause basically evaluates to Between 2017-08-02 And 2017-08-05, which will never be true.
Where do you expect the day element to come in with your files structured as yyyyMM?
I've read thru various posts on here in regards to similiar issues but none have solved my problem.
I manipulate the moment.js date object, and then store it as timestamp.
BUT, when I try to read in that timestamp again, I get that deprecated warning.
""Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info."
I've tried toDate(), format(), moment(myTimeStamp, 'ddd, DD MMM YYYY HH:mm:ss ZZ'); --> all generate the warning...
So, for example, my timestamp will look like this:
const timestamp = '1458586740000'
when I read that back and try to parse out the month/day/year, then the hour/min am/pm, etc... I need to get that timestamp into a moment.js object. Nothing is working for me. Any ideas.
How can I get this timestamp: '1458586740000', into a moment.js object so I can extract date date from it as I need?
EDIT: this is how I am storing the timestamp. So I would need to retrieve it from this.
let timeStamp = Moment(state[_Date])
.add({ hour: state[AMPM] === 'PM'
? +state[Hour] + 12
: state[Hour] ,
minute: state[Min] }).format('x')
The X token indicates a unix timestamp in seconds, and the x token indicates a unix millisecond timestamp (offset).
You appear to have a millisecond timestamp, so you would make a moment out of it by doing the following:
var a = moment('1458586740000', 'x')
It works without ' as well:
var a = moment(1458586740000, 'x')
You can also not specify the x and it should work:
moment(1458586740000)
Because you have a unix offset (milliseconds), not a unix timestamp (seconds), moment.unix is not what you want.
Then you can do the following:
a.format()
"2016-03-21T13:59:00-05:00"
Or you can use any of the other formatting tokens listed here to output whatever result you would like: http://momentjs.com/docs/#/displaying/format/
Based on the code you presented, I think you may be having problems because your timestamp is stored as a string (in ''). Parsing as a string causes an invalid date error, because it attempts to match ISO 8601 format and fails. Specifying that 'x' token will cause it to assume unix offset and work correctly.
I'm trying to create an applescript script that will take a date in the form:
02/20/99
Then, subtract 5 days from the date, and return a date like this:
02/15/99
Here's the basic applescript I have, but, obviously, I'm missing the logic around converting the date into something that I can manipulate (and returning it to something readable by humans).
set itemPath to quoted form of POSIX path of theFile
set dateString to do shell script "awk 'NR == 10 {print $3}' " & itemPath & " -"
set myDueDate to dateString - (5 * days)
set theTask to "Pay AMEX bill"
tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "OFFICE"
set theProject to first flattened context where its name = "Bookkeeping - PMS"
tell theProject to make new task with properties {name:theTask, context:theContext, due date:myDueDate}
end tell
end tell
Thanks in advance!
I think these lines should be sufficient for what you need:
set dateString to "02/20/99"
set thisDate to date dateString
set fiveDaysEarlier to thisDate - 5 * days
log date string of fiveDaysEarlier
log short date string of fiveDaysEarlier
This page has some more examples of the coercions supported when converting strings to objects of date class:
AppleScript Class Reference: date
Also, it probably goes without saying, but the string "02/20/99" is not Y2k compliant, so guesses will have to be made somewhere as to which century this date lies in.
If you get error "FileMaker Pro got an error: Object not found." number -1728, add my before date. e.g,
set thisDate to my date dateString.
When working inside a tell, I think it needs to access methods outside the tell's scope.