Freemarker : Convert unix timestamp string to date format string - datetime

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"]

Related

Convert timestamp to dateTime in MarkLogic

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

In R, take a date string and convert it to datetime format (using lubridate)

In R I am trying to take a date string and convert it to date time format using lubridate but anm getting an error that:
All formats failed to parse. No formats found.
Using this code:
lubridate::as_date("1/2/34")
Shouldn't this just return a formated date time?
as.Date or as_Date needs format. By default, it can parse if the format is %Y-%m-%d. Here, it is not the case. So
lubridate::as_date("1/2/34", format ="%d/%m/%y")
Or more compactly
lubridate::dmy("1/2/34")
Based on the string, it is not clear whether it is day/month/year or month/day/year. Also, for 2-digit year, there is an issue with prefix i.e. it can be either "19" or "20". Here, it would parse at "2034"

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

how convert string without format to dateTime in xquery

I have a transformation in OSB. In the response I receive a string large 40, that represents a date time, but with no specific format. I need to cast this value to dateTime.
For example:
<ns2:fechaHora>{
fn-bea:dateTime-from-string-with-format('dd/MM/yyyy', $row/ns1:fechor)
}</ns2:fechaHora>
Actually I receive for example 01/12/2019, but in the future I will receive other formats, for example: 2019/12/01 or 12/01/2019, and others..
How can I format such a variety of string values and turn them into dataTime?

How to covert mm/dd/yyyy to dd/mm/yyyy

I have a textbox in which date is in format mm/dd/yyyy. I want to convert it from mm/dd/yyyy to dd/mm/yyyy in asp.net with vb to a DateTime variable.
DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture).ToString("dd'/'MM'/'yyyy")
Update: Given that you want to have a DateTime in the end, you can just parse the original format:
DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture)
The date formats are of use only when presenting the date as a string (internally the date does not have a format; it's just a number). If you want to store it in a DateTime all you need to bother about is to interpret the input correctly.
If you are dealing with a DateTime object you convert can like this:
yourDateTime.ToString("dd/MM/yyyy"))

Resources