Announcement

Collapse
No announcement yet.

using Date.parse(x) x="January 3, 2010". Why does it not work?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • using Date.parse(x) x="January 3, 2010". Why does it not work?

    I am reading a file that has two parameters, a date ("Janury 3, 2010" for example) and a constant. Below is part of the program I wrote.

    FVDate1 = "January 3, 2010". It is the line with //************ in it. Why will it not work and what do I need to do to correct this?

    PHP Code:
    var = new File"FVeSignal.txt" );
            if( 
    f.exists() ) {
                
    f.open"rt" );
                var 
    FVDate;
                var 
    FVDate1;
                var 
    FV1;
                var 
    FV;
                while( !
    f.eof() ) {
                    
    FVDate1 f.readln();
                    
    FV1 f.readln();
                    
    ee = new Date()
                    
    FVDate ee.Date.parse(FVDate1)  //************
                    
                    
    if(FVDate == TodayDate) {
                        
    FV FV1;
                        break;
                    }
              }
                    
    f.close(); 

  • #2
    Re: using Date.parse(x) x="January 3, 2010". Why does it not work?

    WantToLearn
    See this article [and specifically the section regarding parse] of the Core JavaScript Guide which is provided in the EFS KnowledgeBase
    FYI I found it by searching the KB for Date.parse()
    Alex


    Originally posted by WantToLearn
    I am reading a file that has two parameters, a date ("Janury 3, 2010" for example) and a constant. Below is part of the program I wrote.

    FVDate1 = "January 3, 2010". It is the line with //************ in it. Why will it not work and what do I need to do to correct this?

    PHP Code:
    var = new File"FVeSignal.txt" );
            if( 
    f.exists() ) {
                
    f.open"rt" );
                var 
    FVDate;
                var 
    FVDate1;
                var 
    FV1;
                var 
    FV;
                while( !
    f.eof() ) {
                    
    FVDate1 f.readln();
                    
    FV1 f.readln();
                    
    ee = new Date()
                    
    FVDate ee.Date.parse(FVDate1)  //************
                    
                    
    if(FVDate == TodayDate) {
                        
    FV FV1;
                        break;
                    }
              }
                    
    f.close(); 

    Comment


    • #3
      Thank you Alex for your quick response. I also found this in KB and it says it has to be a dateString. But FVDate1 is equal to a datestring, namely "January 3, 2010". Can I convert this somehow into a datestring? I don't want to manually write each date in the equation, that would defeat the whole purpose of programming. What am I not seeing?

      Comment


      • #4
        OK, I reread it three more times and printed it below. Maybe there is a misunderstood word somewhere? Date.parse() must be written as a string such as, "January 3, 2010" or "10/20/2010" or "Mon 19 Dec 2005 14:00:00 GMT". It can not be FVDate1 like I want it to, I understand that. How do I get the value of FVDate1, which is "January 3, 2010" or some other date as it reads the data file into Date.parse("January 3, 2010"). That part is not explained in KB.

        I know it is very easy for you, but for me it is mind boggling after playing with it for over 4 hours.

        Any help would be greatly appreciated.


        Syntax
        Date.parse(dateString)

        Parameters
        :
        dateString
        A string representing a date.

        Description
        The parse method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 (local time). This function is useful for setting date values based on string values, for example in conjunction with the setTime method and the Date object.
        Given a string representing a time, parse returns the time value. It accepts the IETF standard date syntax: "Mon, 25 Dec 1995 13:30:00 GMT". It understands the continental US time-zone abbreviations, but for general use, use a time-zone offset, for example, "Mon, 25 Dec 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.
        Because parse is a static method of Date, you always use it as Date.parse(), rather than as a method of a Date object you created.

        Examples
        If IPOdate is an existing Date object, then you can set it to August 9, 1995 as follows:
        IPOdate.setTime(Date.parse("Aug 9, 1995"))

        Comment


        • #5
          WantToLearn
          As indicated in that article
          "Because parse is a static method of Date, you always use it as Date.parse(), rather than as a method of a Date object you created."
          You are instead using it as a method of the ee Date object you created ie ee.Date.parse(...) instead of Date.parse(...)
          If for whatever reason you want to use the ee Date object then pass the date string to that and then use the getTime() method of the Date object to return the milliseconds from 1/1/1970
          Alex


          Originally posted by WantToLearn
          OK, I reread it three more times and printed it below. Maybe there is a misunderstood word somewhere? Date.parse() must be written as a string such as, "January 3, 2010" or "10/20/2010" or "Mon 19 Dec 2005 14:00:00 GMT". It can not be FVDate1 like I want it to, I understand that. How do I get the value of FVDate1, which is "January 3, 2010" or some other date as it reads the data file into Date.parse("January 3, 2010"). That part is not explained in KB.

          I know it is very easy for you, but for me it is mind boggling after playing with it for over 4 hours.

          Any help would be greatly appreciated.


          Syntax
          Date.parse(dateString)

          Parameters
          :
          dateString
          A string representing a date.

          Description
          The parse method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 (local time). This function is useful for setting date values based on string values, for example in conjunction with the setTime method and the Date object.
          Given a string representing a time, parse returns the time value. It accepts the IETF standard date syntax: "Mon, 25 Dec 1995 13:30:00 GMT". It understands the continental US time-zone abbreviations, but for general use, use a time-zone offset, for example, "Mon, 25 Dec 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.
          Because parse is a static method of Date, you always use it as Date.parse(), rather than as a method of a Date object you created.

          Examples
          If IPOdate is an existing Date object, then you can set it to August 9, 1995 as follows:
          IPOdate.setTime(Date.parse("Aug 9, 1995"))

          Comment


          • #6
            Thank you Alex. It works..... of course. OK, you made it clear I don't undertand what an Object or Method is. I wasn't look at that. I will delve into this and learn some more. Thanks again.
            Jack

            Comment

            Working...
            X