Convert timestamp to dateTime in MarkLogic - xquery

I am using xdmp:document-timestamp function to get the timestamp of the most recent update that happened on this document.
Above function returns timestamp as output like: 16222984921692864.
How can I convert this timestamp 16222984921692864 to the human readable xs:dateTime?

We can use the xdmp:timestamp-to-wallclock function to convert timestamp to dateTime.
xdmp:timestamp-to-wallclock(16222984921692864)
returns:
2021-05-29T10:28:12.1692864

Related

convert an epoch timestamp to datetime in azure data factory

I'm working with data flow in azure data factory and i tried to convert an epoch formatted timestamp to date.
the value of the timestamp is '1574067907751' and i tried expressions :
toDate(toTimestamp(1574067907751*1000l))
or
toDate(toTimestamp(toInteger('1574067907751')*1000l,'yyyy-MM-dd HH:mm:ss'))
there is any other way to do that ?
https://learn.microsoft.com/en-us/azure/data-factory/concepts-data-flow-expression-builder#convert-to-dates-or-timestamps
"To convert milliseconds from epoch to a date or timestamp, use toTimestamp(). If time is coming in seconds, multiply by 1,000.
toTimestamp(1574127407*1000l)
The trailing "l" at the end of the previous expression signifies conversion to a long type as inline syntax."

Convert date to other format other than YYYY-MM-DD

I need to convert input date coming in format YYYY-MM-DD. First I convert it into char by following:
TO_CHAR(<date_column>,'YY/MM/DD')
then try to convert it into date for this format:
to_date((TO_CHAR(<date_column>,'YY/MM/DD')),'YY/MM/DD')
As to_date always converts to default date type of YYYY-MM-DD. What other way can I use to convert this into other format. I am using Informatica Powercenter, so I can not find other function other than TO_DATE.
I think we are ignoring basics - to_date() converts to a date format. Now it can be displayed in dd/mm/yyyy depending on setup in your DB client or if you are dumping in a file probably YYYY-MM-DD. And on a date filed you cfan use TO_CHAR o convert it to any format.
So, if your input is a string and is in 'YY/MM/DD' then use TO_CHAR(TO_DATE(imp_yymmdd,'YY/MM/DD'),'DD/MM/YYYY') - output will be a string of your desired format i.e. DD/MM/YYYY.
If your input is a date then use TO_CHAR(imp_date,'DD/MM/YYYY') - output will be a string of your desired format.
Date datatype has no format. You can format a string representing a date.
Assuming your input is date, just use TO_CHAR(yourdate, 'desiredformat').
If your input is a string, you first need to convert it to date then back to string again, with the desired format applied. So:
TO_CHAR(TO_DATE(yourstring, "format-it-comes-in"), "desired-format")
Which in your case would be:
TO_CHAR(TO_DATE(yourstring, "YYYY-MM-DD"), "YY/MM/DD")

Convert string into timestamp in Hive

I have a value '2017-09-27T19:25:15.927-07:00', is there any way to convert this into a timestamp?
I use Hive 1.1.0.
select unix_timestamp("2017-09-27T19:25:15.927-07:00", "yyyy-MM-ddTHH:mm:ss.SSSX") but it trows Bad date/time conversion format
select unix_timestamp("2017-09-27T19:25:15.927-07:00", "yyyy-MM-ddTHH:mm:ss.SSSZZZ") but it returns NULL
The format is yyyy-MM-dd'T'HH:mm:ss.SSSXXX".Note the single quotes surrounding 'T'
select from_unixtime(unix_timestamp("2017-09-27T19:25:15.927-07:00", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"))

Freemarker : Convert unix timestamp string to date format string

I am getting unix timestamp in String format in my ftl file. I want to reformat date to readable string such as "yyyy-MM-dd".
How should I convert timestamp to formatted date string ?
I got date in required format using below code:
calBookingEntry.getStartTime()?number?number_to_datetime?string["yyyy-MM-dd"]

How can I convert a datetime to dd-mmm-yyyy Date format?

I'm using Webdatechooser<<Infragistics control>> for a column which takes the datetime.
I need to convert the value entered (through the Webdatechooser) to dd-mmm-format.
Can I have snippets for that?
The value is a DateTime object so you can use the ToString function of that object to generate the desired output.
((DateTime)WebDateChooser1.Value).ToString("dd-MMM-yyyy");
Should do it.

Resources