That is exactly what my datetime:from-epoch function does.. :)

The reason you have to use xs:dayTimeDuration instead of xs:duration, is
that dayTime and yearMonth durations use (kind of) different scales. 1
month can¹t be converted to days accurately without knowing exactly which
month. The two are not interchangeable. I think that is why you are not
allows to cast strings with xs:duration (think of it as an abstract type),
but have to explicitly use yearMonth versus dayTime instead.

I¹m talking about XQuery 1 though. Things may have shifted for XQuery 3,
but not aware of that..

Cheers,
Geert

On 9/23/16, 11:35 AM, "[email protected] on behalf
of Florent Georges" <[email protected] on behalf of
[email protected]> wrote:

>2 things here:
>
>- your timestamp is not regular Unix time, it seems to count
>milliseconds rather than seconds since the epoch
>
>- it seems you need to xs:dayTimeDuration instead of xs:duration (not
>sure why, I think we introduced xs:duration in XQuery 3.0, but
>MarkLogic does not complain about it per se, just the value it holds)
>
>The following seems to do what you want (given the assumptions above):
>
>let $seconds := 1458797764507
>return
>   xs:dateTime('1970-01-01T00:00:00+00:00')
>      + xs:dayTimeDuration('PT' || ($seconds div 1000) || 'S')
>
>Regards,
>
>-- 
>Florent Georges
>http://fgeorges.org/
>http://h2oconsulting.be/
>
>
>On 23 September 2016 at 11:23, Debin, Infant Jerald (LNG-CON) wrote:
>> Hi,
>>
>>
>>
>> When I use the below command it is throwing error
>>
>>
>>
>> xs:dateTime('1970-01-01T00:00:00+00:00') + xs:duration('PT' ||
>> "1458797764507" || 'S')
>>
>>
>>
>> Error:
>>
>>
>>
>> [1.0-ml] XDMP-EXPR: (err:XPTY0004) xs:dateTime("1970-01-01T00:00:00Z") +
>> xs:duration("P16884233DT9H15M7S") -- Invalid expression
>>
>>
>>
>> Stack trace:
>>
>>
>>
>> at 1:41:
>>
>> 1: xs:dateTime('1970-01-01T00:00:00+00:00') + xs:duration('PT' ||
>> "1458797764507" || 'S')
>>
>>
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Florent
>> Georges
>> Sent: Friday, September 23, 2016 3:26 AM
>> To: MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] Convert unix timestamp to HH/MM/SS
>>in
>> marklogic
>>
>>
>>
>> Hi,
>>
>>
>>
>> You should be able to use the following expression, given $seconds is
>>your
>> timestamp, to get a date-time.  I am not sure about the limits on the
>>number
>> of seconds you can have in a duration, though:
>>
>>
>>
>> xs:dateTime('1970-01-01T00:00:00+00:00')
>>
>>    + xs:duration('PT' || $seconds || 'S')
>>
>>
>>
>> Regards,
>>
>>
>>
>> --
>>
>> Florent Georges
>>
>> http://fgeorges.org/
>>
>> http://h2oconsulting.be/
>>
>>
>>
>>
>>
>> On 23 September 2016 at 09:14, Debin, Infant Jerald (LNG-CON) wrote:
>>
>>> Hi,
>>
>>>
>>
>>>
>>
>>>
>>
>>> Is there a way to convert the unix timestamp to HH/MM/SS format in
>>> marklogic
>>
>>> using xquery.
>>
>>>
>>
>>>
>>
>>>
>>
>>> Unit timestamp that is in xml is in below ,
>>
>>>
>>
>>>
>>
>>>
>>
>>> <timestamp>1472812470453</timestamp>
>>
>>>
>>
>>>
>>
>>>
>>
>>> Thanks,
>>
>>>
>>
>>> Debin
>>
>>>
>>
>>>
>>
>>> _______________________________________________
>>
>>> General mailing list
>>
>>> [email protected]
>>
>>> Manage your subscription at:
>>
>>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>>
>>
>> _______________________________________________
>>
>> General mailing list
>>
>> [email protected]
>>
>> Manage your subscription at:
>>
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> Manage your subscription at:
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>_______________________________________________
>General mailing list
>[email protected]
>Manage your subscription at:
>http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to