<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How to convert local time to system time? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069750#M726676</link>
    <description>&lt;P&gt;HI,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to convert this date by using below code:&lt;/P&gt;
&lt;P&gt;var gr = new GlideDateTime(Date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the question is , is this date only or date time both as well as is this In same format as system uses. If no then we have to convert this.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Ashutosh Munot&lt;/P&gt;</description>
    <pubDate>Mon, 19 Mar 2018 13:44:42 GMT</pubDate>
    <dc:creator>Ashutosh Munot1</dc:creator>
    <dc:date>2018-03-19T13:44:42Z</dc:date>
    <item>
      <title>How to convert local time to system time?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069749#M726675</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;I have a GlideRecord script&amp;nbsp;similar to&amp;nbsp;below:&lt;/P&gt;
&lt;P&gt;=====&lt;/P&gt;
&lt;P&gt;var gr = new GlideRecord('incident');&lt;/P&gt;
&lt;P&gt;gr.addQuery('sys_created_on', '&amp;gt;', Date)&lt;/P&gt;
&lt;P&gt;.....&lt;/P&gt;
&lt;P&gt;=====&lt;/P&gt;
&lt;P&gt;The Date variable will come from an api call as a parameter sent by the client. Basically they want to know how many records were created at a certain range of dates. But they will send the date/time in their local time. How do I convert their local time to ServiceNow's system time (UTC) so I can put that date into the addQuery?&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 12:30:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069749#M726675</guid>
      <dc:creator>kiki330611</dc:creator>
      <dc:date>2018-03-19T12:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert local time to system time?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069750#M726676</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to convert this date by using below code:&lt;/P&gt;
&lt;P&gt;var gr = new GlideDateTime(Date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the question is , is this date only or date time both as well as is this In same format as system uses. If no then we have to convert this.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Ashutosh Munot&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 13:44:42 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069750#M726676</guid>
      <dc:creator>Ashutosh Munot1</dc:creator>
      <dc:date>2018-03-19T13:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert local time to system time?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069751#M726677</link>
      <description>&lt;P&gt;There are a couple things to remember when doing date/time operations.&lt;/P&gt;
&lt;OL&gt;&lt;LI&gt;The system stores all date/time fields as UTC - or at least it believes it does.&lt;/LI&gt;&lt;LI&gt;If you want to apply your local to the value retrieved from a field, use getDisplayValue().&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;If you want UTC, use getValue()&lt;/LI&gt;&lt;LI&gt;2 and 3 also apply to setDisplayValue() and setValue().&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Once you keep it straight in your head when a TZ is applied (e.g. display values) and when it is not (getValue()/setValue()) everything else becomes pretty easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based your requirement, you want to take the value the user gave you, and&amp;nbsp;strip the timezone - something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;// change user.date to whatever variable the user gave you&lt;/P&gt;
&lt;P&gt;var gr = new GlideRecord('incident');&lt;/P&gt;
&lt;P&gt;var date =&amp;nbsp;new GlideDateTime();&lt;/P&gt;
&lt;P&gt;date.setDisplayValue(user.date); // insert it in to the variable with TZ applied, so the internal value has no TZ&lt;/P&gt;
&lt;P&gt;gr.addQuery('sys_created_on', '&amp;gt;', date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Standard disclaimer: The following code is untested, requires review and potential modifications.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 13:55:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069751#M726677</guid>
      <dc:creator>Chuck Tomasi</dc:creator>
      <dc:date>2018-03-19T13:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert local time to system time?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069752#M726678</link>
      <description>&lt;P&gt;Hi Chuck,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One quick question. If the date is coming in different format, what can we do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Ashutosh Munot&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 14:29:31 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069752#M726678</guid>
      <dc:creator>Ashutosh Munot1</dc:creator>
      <dc:date>2018-03-19T14:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert local time to system time?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069753#M726679</link>
      <description>&lt;P&gt;My recommendation is to use a date or date/time field to allow them to pick. Then the format is known.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GlideDateTime() is pretty good about understanding the known formats within ServiceNow. If you get outside of that (using dots instead of dashes for example) then you're going to have issues. I definitely would not leave the input as a string field or you'll never get good coverage on the parsing.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 17:41:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069753#M726679</guid>
      <dc:creator>Chuck Tomasi</dc:creator>
      <dc:date>2018-03-19T17:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert local time to system time?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069754#M726680</link>
      <description>&lt;P&gt;Thanks Chuck! That solved my problem!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 12:32:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-local-time-to-system-time/m-p/2069754#M726680</guid>
      <dc:creator>kiki330611</dc:creator>
      <dc:date>2018-03-20T12:32:57Z</dc:date>
    </item>
  </channel>
</rss>

