<?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: getByFormat is not working as expected in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363240#M20166</link>
    <description>&lt;P&gt;ohk got the issue. try now , i have tested it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;var a = '2019-12-31 08:00:00';&lt;BR /&gt;var gDateTime = new GlideDateTime(a);&lt;BR /&gt;var gDate = gDateTime.getDate();&lt;BR /&gt;gs.print(gDate); // prints - 2019-12-31 - correct value&lt;BR /&gt;&lt;STRONG&gt;var longDateTime = gDate.getByFormat("MMMM d, yyyy");&lt;/STRONG&gt;&lt;BR /&gt;gs.print(longDateTime); // prints - December 31, 2020 - wrong year&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;If my answer helped you, kindly mark it as correct and helpful.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Mar 2020 06:31:43 GMT</pubDate>
    <dc:creator>hvrdhn88</dc:creator>
    <dc:date>2020-03-13T06:31:43Z</dc:date>
    <item>
      <title>getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363235#M20161</link>
      <description>&lt;P&gt;The below script is not working as expected.&lt;/P&gt;
&lt;P&gt;The variable longDateTime should print value as "December 31, 2019" but it is printing as "December 31, 2020".&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var current = new GlideRecord('proc_po');
current.addEncodedQuery('u_amat_poSTARTSWITH4400475274');
current.query();
if(current.next()){
var gDateTime = new GlideDateTime(current.po_date.getDisplayValue());
var gDate = gDateTime.getDate();
gs.print(gDate); // prints - 2019-12-31 - correct value
var longDateTime = gDate.getByFormat("MMMM dd, YYYY");
gs.print(longDateTime); // prints - December 31, 2020 - wrong year
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Need help to fix this.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Francis Xavier K.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 05:52:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363235#M20161</guid>
      <dc:creator>xavifrancis</dc:creator>
      <dc:date>2020-03-13T05:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363236#M20162</link>
      <description>&lt;P&gt;Hi Francis,&lt;/P&gt;
&lt;P&gt;can you print the gDateTime value?&lt;/P&gt;
&lt;P&gt;Mark &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Correct if this solves your issue and also mark &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; Helpful if you find my response worthy based on the impact.&lt;BR /&gt;Thanks&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 05:59:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363236#M20162</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-03-13T05:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363237#M20163</link>
      <description>&lt;P&gt;Hi Ankur,&lt;/P&gt;
&lt;P&gt;below is the output we are getting for gDateTime.&lt;/P&gt;
&lt;PRE&gt;2019-12-31 13:30:00&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Mar 2020 06:10:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363237#M20163</guid>
      <dc:creator>xavifrancis</dc:creator>
      <dc:date>2020-03-13T06:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363238#M20164</link>
      <description>&lt;P&gt;try now.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;var current = new GlideRecord('proc_po');
current.addEncodedQuery('u_amat_poSTARTSWITH4400475274');
current.query();
if(current.next()){
var gDateTime = new GlideDateTime(current.po_date);

gDateTime.getDisplayValueInternal();

var gDate = gDateTime.getDate();
gs.print(gDate); // prints - 2019-12-31 - correct value
var longDateTime = gDate.getByFormat("MMMM dd, YYYY");
gs.print(longDateTime); // prints - December 31, 2020 - wrong year
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Mar 2020 06:12:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363238#M20164</guid>
      <dc:creator>hvrdhn88</dc:creator>
      <dc:date>2020-03-13T06:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363239#M20165</link>
      <description>&lt;P&gt;It gives the same result.&lt;/P&gt;
&lt;P&gt;Check the below simplified script:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var a = '2019-12-31 08:00:00';
var gDateTime = new GlideDateTime(a);
var gDate = gDateTime.getDate();
gs.print(gDate); // prints - 2019-12-31 - correct value
var longDateTime = gDate.getByFormat("MMMM dd, YYYY");
gs.print(longDateTime); // prints - December 31, 2020 - wrong year
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which gives the same result.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 06:29:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363239#M20165</guid>
      <dc:creator>xavifrancis</dc:creator>
      <dc:date>2020-03-13T06:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363240#M20166</link>
      <description>&lt;P&gt;ohk got the issue. try now , i have tested it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;var a = '2019-12-31 08:00:00';&lt;BR /&gt;var gDateTime = new GlideDateTime(a);&lt;BR /&gt;var gDate = gDateTime.getDate();&lt;BR /&gt;gs.print(gDate); // prints - 2019-12-31 - correct value&lt;BR /&gt;&lt;STRONG&gt;var longDateTime = gDate.getByFormat("MMMM d, yyyy");&lt;/STRONG&gt;&lt;BR /&gt;gs.print(longDateTime); // prints - December 31, 2020 - wrong year&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;If my answer helped you, kindly mark it as correct and helpful.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 06:31:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363240#M20166</guid>
      <dc:creator>hvrdhn88</dc:creator>
      <dc:date>2020-03-13T06:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363241#M20167</link>
      <description>&lt;P&gt;for future reference, you can refer the below link for correct date format string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.talend.com/reader/3zI67zZ9kaoTVCjNoXuEyw/YHc8JcQYJ7mWCehcQRTEIw" rel="nofollow"&gt;https://help.talend.com/reader/3zI67zZ9kaoTVCjNoXuEyw/YHc8JcQYJ7mWCehcQRTEIw&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="cm-comment-text cm-comment-view-mode ng-scope"&gt;
&lt;DIV class="cm-comment-body"&gt;
&lt;DIV class="cm-comment-text-info"&gt;
&lt;P class="ng-scope"&gt;&lt;EM&gt;&lt;STRONG&gt;If my answer helped you, kindly mark it as correct and helpful.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;DIV class="cm-attachments-body"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="cm-comment-footer cm-common-light-color ng-scope"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 13 Mar 2020 06:33:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363241#M20167</guid>
      <dc:creator>hvrdhn88</dc:creator>
      <dc:date>2020-03-13T06:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363242#M20168</link>
      <description>&lt;P&gt;put the YYYY as yyyyy (from upper case to lower case).&lt;/P&gt;
&lt;P&gt;the upper case format gives back 'year of week', 31 december could be in week 1 of the next year.&lt;/P&gt;
&lt;P&gt;the lower case format gives back 'current year', what you are looking for.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 06:35:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363242#M20168</guid>
      <dc:creator>Jorn van Beek</dc:creator>
      <dc:date>2020-03-13T06:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: getByFormat is not working as expected</title>
      <link>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363243#M20169</link>
      <description>&lt;P&gt;Thank you Harshvardhan...&lt;/P&gt;
&lt;P&gt;It works fine now&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 06:42:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getbyformat-is-not-working-as-expected/m-p/1363243#M20169</guid>
      <dc:creator>xavifrancis</dc:creator>
      <dc:date>2020-03-13T06:42:10Z</dc:date>
    </item>
  </channel>
</rss>

