[MarkLogic Dev General] return current dateTime in UTC format

mcundiff1 at comcast.net mcundiff1 at comcast.net
Sat May 11 15:16:30 PDT 2013


Ron (and David), 

Thanks. Yes, it "felt a bit wrong" to me too to have to slice and dice the dateTime as a string. I thought since this: 

2013-05-11T17:01:18Z 

is billed elsewhere as "the standard W3C date and time format" that there was probably a built-in function for it. 

Morgan 

----- Original Message -----
From: "Ron Hitchens" <ron at ronsoft.com> 
To: "MarkLogic Developer Discussion" <general at developer.marklogic.com> 
Sent: Saturday, May 11, 2013 5:28:29 PM 
Subject: Re: [MarkLogic Dev General] return current dateTime in UTC format 


Try something like this (using XQuery 3.0 concatenation syntax): 


declare variable $orig-time := xs:dateTime ("2013-05-11T10:38:45.333548-04:00"); 

declare variable $utc-time := fn:adjust-dateTime-to-timezone ($orig-time, xs:dayTimeDuration('PT0H')); 

declare variable $adjusted-time := xs:dateTime (fn:substring (fn:string ($utc-time), 1, 19) || "Z"); 

$orig-time, $utc-time, $adjusted-time 


It feels a bit wrong to serialize an xs:dateTime to xs:string to truncate 
the fractional seconds. It would be better to be able to apply the fn:floor 
function to the seconds part. But there isn't an xs:dateTime constructor that 
takes the individual year, month, etc values, so you can only manipulate the 
string representation to make changes. 

--- 
Ron Hitchens {mailto:ron at ronsoft.com} Ronsoft Technologies 
+44 7879 358 212 (voice) http://www.ronsoft.com 
+1 707 924 3878 (fax) Bit Twiddling At Its Finest 
"No amount of belief establishes any fact." -Unknown 


On May 11, 2013, at 6:41 PM, David Lee <David.Lee at marklogic.com> wrote: 

> toss in an fn:replace() to strip off the fractional seconds, or you can use format-dateTime() on the adjusted time, 
> but dont have it put a timezone on just concatentate the "Z" 
> or you can construct the string yourself by extracting out all the values and concatenating them or 
> recreate a dateTime with no fractional seconds. 
> Lots of ways to skin the cat. 
> 
> 
> ----------------------------------------------------------------------------- 
> David Lee 
> Lead Engineer 
> MarkLogic Corporation 
> dlee at marklogic.com 
> Phone: +1 812-482-5224 
> Cell: +1 812-630-7622 
> www.marklogic.com 
> 
> 
> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of mcundiff1 at comcast.net 
> Sent: Saturday, May 11, 2013 1:07 PM 
> To: MarkLogic Developer Discussion 
> Subject: Re: [MarkLogic Dev General] return current dateTime in UTC format 
> 
> Ellis, 
> 
> Thanks, that's close. 
> 
> fn:adjust-dateTime-to-timezone(current-dateTime(),xs:dayTimeDuration('PT0H')) 
> 
> returns: 
> 2013-05-11T17:01:18.209498Z 
> 
> I need this: 
> 2013-05-11T17:01:18Z 
> 
> Morgan 
> 
> From: "Ellis Pritchard" <ellis at mobi1.co.uk> 
> To: "MarkLogic Developer Discussion" <general at developer.marklogic.com> 
> Sent: Saturday, May 11, 2013 12:21:06 PM 
> Subject: Re: [MarkLogic Dev General] return current dateTime in UTC format 
> 
> fn:adjust-dateTime-to-timezone($dateTime,xs:dayTimeDuration('PT0H')) 
> 
> Ellis. 
> 
> On 11 May 2013, at 15:52, mcundiff1 at comcast.net wrote: 
> 
> The current-dateTime() function returns the following: 
> 
> 2013-05-11T10:38:45.333548-04:00 
> 
> I need to have it expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z") like: 
> 
> 1994-11-05T13:15:30Z 
> 
> How is that done? With format-dateTime()? 
> 
> Thanks, 
> Morgan 
> _______________________________________________ 
> 
> General mailing list 
> General at developer.marklogic.com 
> http://developer.marklogic.com/mailman/listinfo/general 
> 
> _______________________________________________ 
> General mailing list 
> General at developer.marklogic.com 
> http://developer.marklogic.com/mailman/listinfo/general 
> _______________________________________________ 
> General mailing list 
> General at developer.marklogic.com 
> http://developer.marklogic.com/mailman/listinfo/general 

_______________________________________________ 
General mailing list 
General at developer.marklogic.com 
http://developer.marklogic.com/mailman/listinfo/general 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20130511/791fe73c/attachment.html 


More information about the General mailing list