How can I convert a date contained in a string into a date value with XPath?
I got the string by formatting a date value with fn:format-date, and now I want the date value from the formatted string.
Thank you,
You can use EXSLT's date:date(string). It is implemented in most XSLT processors but also as a pure XSLT function.
Documentation: http://www.exslt.org/date/functions/date/index.html.
Related
I'm trying to get DAYID as string in format YYYYMMDD, however its not working correctly.
I have a timestamp field, I take first 10 characters and convert it into date (working correctly)
toDate(substring(EventTimestamp,1,10))
-- 2021-03-24
However when I try to convert to string using below expression, I;m getting wrong answer. I;m getting the Day as 83.
toString(toDate(substring(EventTimestamp,1,10)),'YYYYMMDD')
--20210383
Date format characters are case-sensitive as per this answer here, so use yyyyMMdd instead.
An example using formatDateTime:
#formatDateTime(utcnow(), 'yyyyMMdd')
I am trying to convert a string to a numeric in SAS. Currently, it looks like 05/23/2007. My code so far is
Data Data2;
Set Data1;
Input(Date, mmddyy10w.);
If Date > '07/15/2009'd;
run;
I get an error saying that the format mmddyy10w. cannot be recognized. Does anyone know how to fix this?
Correct informat to read date in the scenario is mmddyy10., date literal should be like '14Jul2009'd. as shown in below example
Data Data2;
date= Input('07/15/2009',mmddyy10.);
format date mmddyy10.;
If Date > '14Jul2009'd;
run;
below is the link, which gives good idea format and informats of dates in SAS.
https://support.sas.com/resources/papers/proceedings15/1334-2015.pdf
How do I convert a numeric in Julian format 'yyyyddd' to a proper Date value in Teradata?
For example from '2014001' to '2014-01-01'.
Please provide two examples, first when '2014001' is a numeric and second when it is a character.
Many Thanks!
After some trial-and-error I've found the answer.
If the data is character, then:
Cast(<Column Name> As Date Format ‘yyyyddd’)
If the data is numeric, then:
Cast(Cast(<Column Name> As Char(7)) As Date Format ‘yyyyddd’)
in DB2 I've got date values stored as varchar in the form 'DD-Mon-YY' (e.g. 25-Jun-13). I'd like to convert these into DB2 compatible date formats using the TO_DATE function but every date conversion format I've tried gives me an error.
e.g. I've tried TO_DATE('25-Jun-13', 'YYYYMMDD') and TO_DATE('25-Jun-13', DDMMYYYY) and I always get something like "25-Jun-13" cannot be interpreted using format string "DDMMYYYY" for the TIMESTAMP_FORMAT function.
Does anyone know if there is a format string that I can use?
I think you're looking for:
DATE(TIMESTAMP_FORMAT(#your_date, 'DD-Mon-YY'))
Aside: TO_DATE is just a synonym for TIMESTAMP_FORMAT.
to_date('string', 'template')
the date format of the string must match the template
MM is month as number
MON is MONth as abbreviation
Example
select to_date('20130625', 'YYYYMMDD') as YYYYMMDD
,to_date('25-Jun-2013', 'DD-MON-YYYY') as DDMONYYYY
from sysibm.sysdummy1
YYYYMMDD DDMONYYYY
2013-06-25 00:00:00.0 2013-06-25 00:00:00.0
Try that
TO_DATE(#your_string, 'yyyy/mm/dd')
I am having a problem converting a date/time string to an NSDate.
The date string I need to convert is: 2002-12-24T00:00:00-07:00
My date format string is currently yyyy-MM-dd'T'HH:mm:ssZZZ
The problem is the colon in the time zone.
ZZZ returns a string like: -0700 (without the colon)
How can I convert a string WITH a colon in the time zone?
Thanks
I suggest doing some string manipulation so it is in a form that dateWithString can more easily accept - how about using stringByReplacingOccurrencesOfString one or more times to get rid of the colon?
dateWithString wants:
YYYY-MM-DD HH:MM:SS ±HHMM
you have:
yyyy-MM-dd'T'HH:mm:ssZZZ
You will probably need to use some combination of componentsSeparatedByString (to get rid of the 'T' part, unless you have a small range of values possible for T, and perhaps write yourself a small function to convert ssZZZ into +HHMM.