Author Topic: jArchi - parsing dates  (Read 248 times)

Alberto

  • Active Member
  • ***
  • Posts: 64
  • Twitter: @albertodmendoza
jArchi - parsing dates
« on: January 29, 2020, 19:21:08 PM »
What am I doing wrong? This works on the browser, but not on jArchi. Why?

var mydate= Date('2011-04-11');
console.log(mydate)

returns:
Wed Jan 29 2020 13:50:53 GMT-0500 (EST)  <-- current timestamp


Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: jArchi - parsing dates
« Reply #1 on: January 29, 2020, 19:26:21 PM »
Try:

Code: [Select]
var mydate = new Date('2011-04-11');
console.log(mydate.toString());

See https://www.w3schools.com/jsref/jsref_obj_date.asp
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Alberto

  • Active Member
  • ***
  • Posts: 64
  • Twitter: @albertodmendoza
Re: jArchi - parsing dates
« Reply #2 on: January 29, 2020, 20:34:34 PM »
I see now... I was trying to do a simple compare dates and I had a couple of things wrong.  For example, these two scripts output the same, but in one I'm guessing today is undefined, yet it prints the current timestamp ( ??? ?). JS is weird.

Code: [Select]
var today = Date();
    console.log(today.toString());
var mydate = new Date('2011-04-11');
    console.log(mydate.toString());
console.log(today > mydate);
console.log(today < mydate);

Code: [Select]
var today = new Date();
    console.log(today.toString());
var mydate = new Date('2011-04-11');
    console.log(mydate.toString());
console.log(today > mydate);
console.log(today < mydate);