I have a date in format Wed, 09 Dec 2020 10:57:15 GMT and want turn it into 09/12/2020.
If i do it with =to_date(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b"))) it works - the output is, like expected 09/12/2020.
But if i add IFERROR, like =iferror(to_date(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b"))),"") the date turns into value, like 44174.
How can i achive the correct date displaying with iferror?
use:
=IFERROR(TEXT(DATEVALUE(REGEXEXTRACT(B2, "\b[0-9]{2}\s\D{3}\s[0-9]{4}\b")),
"dd/mm/yyyy"))
I'm not positive why it works, but the following - just built on what you'd done - worked for me:
=IFERROR(to_date(text(to_date(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b"))),"mm/dd/yyyy")))
BTW, i figured it out to get date displayed through changing of the order of IFERROR and TO_DATE.
The working formula is now =to_date(iferror(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b")),"")).
Related
I want transform the string
Thu, 21 Jan 2021 09:48:38 +0100
in timestamp format "%yyyy-%mm-%dd %hh.%nn.%ss.6"
how to do?
Thank you
Check out the StringToTimestamp function and the other type conversion functions in DataStage.
You could also work with string manipulation first.
Note that you have not provided the information about the fraction of the second yet.
I am trying to retrieve current date time in RFC1123 date format in XSLT.
has anybody tried this using XSL2.0?
I have seen code for converting various date times based on zone in XSLT2.0 and to format in specific date time format such yyyy/mm/dd or YYYY:MM:DDTHH:MM:SS.0Z, but couldnt find a way to format it to show like this
Tue, 09 Jul 2019 20:34:29 GMT
concat(date:add('1970-01-01T00:00:00',concat('PT',floor(dp:time-value() div 1000),'S')),':',dp:time-value() mod 1000)
This returns in GMT format like this 2019-07-09T21:01:26:547
How to format it for - Tue, 09 Jul 2019 20:34:29 GMT using XSLT2.0?
Use current-dateTime() to get the current date and time and then use format-dateTime to format it as needed, see the spec https://www.w3.org/TR/xslt20/#function-format-dateTime on details: a picture string
'[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]'
on my machine in German summer time gives
format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')
as
Wed, 10 July 12:01:13 GMT+02:00
This is meant as an example on the use of format-dateTime, I haven't checked the exact details of the RFC you cited to try to implement the exact requirements.
Thanks for quick reply, your solution worked using Altova XML Spy, but unfortunately it didnt worked for me in Datapower using XSLT2.0, Not sure what was wrong, may be some issue with DP firmware version.
just for other users to make this post more helpful. I tried below 2 options which didnt work for me, but might be useful for others.
using XSLT
<xsl:value-of select="java:java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC))"></xsl:value-of>
<xsl:value-of select="format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')"/>
So I used Gateway script to get same date format which I was looking for and stored in context variable using below
var dateNeeded = new Date()).toUTCString(); //Thu, 11 Jul 2019 21:08:12 GMT
I have used TalendDate.addDate(TalendDate.getCurrentDate(),-1,"DD") and the out put is "Wed Dec 28 23:51:27 IST 2016" .
I want it in "2016-12-28" format.
Is there any way to get that?
Thanks in advance.
This code will format it how you want it.
TalendDate.formatDate("yyyy-MM-dd",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"DD"))
Be sure that in your output component, a date model is defined for this field.
I'm trying to format a date in Tibco Businessworks 6.2.2 in the following format:
06-AUG-2015 12:11 AM
I've found the picture string on several websites for xpath that, according to those who use them, will format the date like this. I've not been able to figure out how to only get the AUG instead of AUGUST without JUNE and JULY showing up as JUN and JUL.
Here is the xpath I'm using:
format-dateTime(current-dateTime(), '[D01]-[MNn, *-3]-[Y0001] [h01]:[m01] [PN]')
Here is the output I'm getting:
06-August-2015 12:11 AM
Any and all information is greatly appreciated.
Try this :
format-dateTime(current-dateTime(), '[D01]-[MN, *-3]-[Y0001] [h01]:[m01] [PN]')
Output :
15-DEC-2015 05:56 P.M.
ref : http://www.w3.org/TR/xslt20/#date-time-examples
In Tibco BW you can use substring on the final output - for the month'AUGUST' with index from 0 to 3. But this seems to be a work around.
A better approach is to write a common process of Date formtter with JavaCode activity from Java Palette. It doesn't and need any specific jar/lib import.
new SimpleDateFormat("yyyy-MMM-dd HH:mm a").format(new Date())
have you tried MMM in stead of MNn?
I used this function. (BW 5.12)
tib:format-dateTime('dd-MMM-yyyy hh:mm a', current-dateTime())
Out
06-Jul-2017 11:34 AM
I'm having some problems converting a string to a date object in google apps script.
My dates are in the following format, from a 3rd party API:
2013-01-17T17:34:50.507
I am attempting to convert this to a Date object:
return Date(stringDate);
And this is being returned:
Thu Jan 01 01:00:00 GMT+01:00 1970
Can someone tell me what i'm doing wrong, and how to resolve this issue ?
With moment.js, it is as easy as this to parse any of ISO 8601 format.
var date = Moment.moment("2013-01-17T17:34:50.507").toDate();
You can use moment.js to parse your arbitrary date string as well.
To use moment.js in GAS, you just need to add it in the script editor.
Open your script in GAS script editor and go to "Resources" then "Libraries...", then put this project key MHMchiX6c1bwSqGM1PZiW_PxhMjh3Sh48 and click "Add". Choose the version from the dropdown, then click "Save". Now, you are ready to use moment.js in GAS.
moment.js can be used to parse date string, create formatted date string, and many other date manipulation. Thanks to the author!
You can find the moment.js documentation here.
It doesn't appear that the Date object knows how to handle that date. The date is in ISO 8601 format. Javascript can handle Dates if they are given timezone information.
You will have to do some testing, but if those dates given to you are in UTC time, then just add a Z to the end of the date string before you call new Date().
Edit: The Apps Script Date object can't seem to handle a timezone other than UTC when parsing a Date. I opened an issue for it.
It doesn't work in GScript, at least for me at the time I'm writing it.
This post serves a working alternative: How do I format this date string so that google scripts recognizes it?
As of now new Date() seems to work:
var dT = new Date("2013-01-17T17:34:50.507");
console.info("dT: %s or %d", dT, dT.getTime());
returns dT: Thu Jan 17 17:34:50 GMT+01:00 2013 or 1.358440490507E12 in Google Apps Script