get the date:time by xsl - xslt

currently I'm using xsl to get the min and max value of #last_updated_time in a sharepoint list, the type is string (like 9/14/2012 1:26:23 PM)
so how can I display the earliest and latest time?
P.S. I try to remove all things but number,then convert to the int, then do the compare, but how to convert that, can anybody show me an approach?

You'll find it much easier to manipulate dates and times in XSLT (especially in XSLT 2.0) if you use international format (2012-14-09T13:26:23) rather than US localized format. So first, if your data is in US format, write code to translate it to ISO format. (That's a simple exercise in string manipulation).
Once you're there, you can use the XSLT 2.0 min() and max() functions to find the earliest and latest in a set of dates or date/time values. Or in XSLT 1.0, you can sort them and select the first and last in sorted order.

Related

XSLT 1.0 - Compare date values and offset by -15 days

I am trying to compare to date values that are being passed into XSLT with the format of MMDDYY, for example: 01022020 (Jan 2, 2020). I am using the below snippet of code in the test:
<xsl:if test="(E_Payclass ='FT') and (E_Status ='TERMINATED') and (E_TermDate < E_PayEnd_Date)">
In an example, the dates are:
E_TermDate: 072017
E_PayEnd_Date: 020120
When running this file, I get the 072017 appearing even though it is actually less than the current date. It seems to me that the file is actually taking the number literally (which is most likely what is supposed to happen) and returning it since its technically greater than 020120.
Overall I am trying to accomplish an outcome in the test that basically would take the E_PayEnd_Date as an actual date, and only return E_TermDate if it is within 15 days prior to it.
Does anyone know how to do that in XSLT 1.0 within an if test statement?

convert milliseconds to date in xslt 1.0

I am trying to convert date which is in milliseconds , e.g. the input xml has 1088499889000 that corresponds to the date 2004-06-29 09:04:49.000GMT.
To try and do this within XSLT they do not seem to have functions for this. Are there any extensions available that I could use for this conversion using xslt 1.0.
Thanks

How to convert imported date variable to the original format in Stata?

My original date variable is like this 19jun2015 16:52:04. After importing, it looks like this: 1.77065e+12
The storage type for the new imported variable is str11 and display format is %11s
I wonder how I can restore it back to date format?
William Lisowski gives excellent advice in his comment. For anyone using date-times in Stata, there is a minimal level of understanding without which confusion and outright error are unavoidable. Only study of the help so that your specific needs are understood can solve your difficulty.
There is a lack of detail in the question which makes precise advice difficult (imported -- from what kind of file? using which commands and/or third party programs?), except to diagnose that your dates are messed up and can only be corrected by going back to the original source.
Date strings such as "19jun2015 16:52:04" can be held in Stata as strings but to be useful they need to be converted to double numeric variables which hold the number of milliseconds since the beginning of 1960. This is a number that people cannot interpret, but Stata provides display formats so that displayed dates are intelligible.
Your example is when converted a number of the order of a trillion but if held as a string with only 6 significant figures you have, at a minimum, lost detail irretrievably.
These individual examples make my points concrete. di is an abbreviation for the display command.
clock() (and also Clock(), not shown or discussed here: see the help) converts string dates to milliseconds since Stata's origin. With a variable, you would use generate double.
. di %23.0f clock("19jun2015 16:52:04", "DMY hms")
1750351924000
If displayed with a specific format, you can check that Stata is interpreting your date-times correctly. There are also many small variations on the default %tc format to control precise display of date-time elements.
. di %tc clock("19jun2015 16:52:04", "DMY hms")
19jun2015 16:52:04
The first example shows that even date-times which are recent dates (~2016) and in integer seconds need 10 significant figures to be accurate; the default display gives 4; somehow you have 6, but that is not enough.
. di clock("19jun2015 16:52:04", "DMY hms")
1.750e+12
You need to import the dates again. If you import them exactly as shown, the rest can be done in Stata.
See https://en.wikipedia.org/wiki/Significant_figures if that phrase is unfamiliar.

Deduct milliseconds from DateTime in xslt

I have a dateTime in this format: 2015-04-29T01:30:27.058Z and time difference of 5000milliseconds. Is there any XSLT function which can deduct this time difference and produce an output of a dateTime?
In XSLT 2.0 or later (requires an XSLT 2.0 processor like Saxon 9 or XmlPrime) you can use arithmetic with xs:dateTime and xs:dayTimeDuration, for instance
xs:dateTime('2015-04-29T01:30:27.058Z') + xs:dayTimeDuration('-PT0.058S')
computes a new xs:dateTime 2015-04-29T01:30:27Z.
The XML schema namespace assumed for the prefix xs is http://www.w3.org/2001/XMLSchema.
See http://www.datypic.com/sc/xsd/t-xsd_dayTimeDuration.html on how dayTimeDurations can be written.
So with that version of the language my suggestion is to make use of those two data types and the arithmetic operations provided instead of going to milliseconds for computations.
In XSLT 2.0,
(xs:dateTime($timeStamp) - xs:dateTime('2000-01-01T00:00:00Z'))
div xs:dayTimeDuration('PT0.001S')
gives the number of milliseconds since the start of the current century.

XSLT 2.0 How to change default formatting for numbers?

In XSLT 1.0 (using Xalan), outputting the result of:
<xsl:variable name="source0" select="number(num3)"/>
<xsl:value-of select="$source0"/>
was the number spelled out as 2011234. But in XSLT 2.0 (using Saxon), it shows up as 2.011234E6. I want it to always display as 2011234 in the Saxon/2.0 case.
Is there a way to set the default picture string for whenever it outputs a number?
I saw decimal-format, but that just affects picture strings, it doesn't set number formatting. I can't just throw format-number everywhere since then I'd have to check datatypes everywhere and... it would be a mess.
There is no way to express in XSLT 2.0 (or XSLT 1.0) that every time a number value is output it must be in a "default" format, without ussing fn:format-number() or xsl:decimal-format or op:cast or built-in type constructors. The only way that every number will be consider of some specific type is that a schema has been declared for the input (so it's a PSVI) and you run the transformation with schema-awere processor.