Results 1 to 4 of 4

Thread: Date Minus Two Script

  1. #1
    Join Date
    Aug 2009
    Location
    charset utf-8
    Posts
    135
    Thanks
    4
    Thanked 5 Times in 5 Posts

    Default Date Minus Two Script

    I need a script that will print todays date minus two days
    I found one in VB Script, but how can I make it JavaScript?
    Code:
    <script type="text/vbscript">
    document.write(Date -2 & "<p> </p>")
    </script>
    Please keep this in JavaScript form and discuss.....

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    If this is one of those homework assignments type things and you just are too lazy to do the work, we cannot be specific. If not, please explain why you would want to do this.

    That said:

    Not knowing PHP well, I'm unclear as to exactly what you are after. However, in javascript the 'date' is the date number in the month - nothing more, nothing less. To get that number minus two, there can be two approaches. One would be to set a current Date Object back two days and and then retrieve the date number from it. This would allow for crossover into a previous month (where applicable) as the Date Object automatically compensates for that sort of thing. Like if you set a January 1st Date Object back 2 days, you get December 30th - the result would be 30. But if you merely took the date number of a current Date Object of January 1st and subtracted 2 from it, you would get -1.

    For more information on how the Date Object works in javascript, see:

    http://www.w3schools.com/jS/js_obj_date.asp

    and:

    http://www.w3schools.com/jsref/jsref_obj_date.asp
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2009
    Location
    charset utf-8
    Posts
    135
    Thanks
    4
    Thanked 5 Times in 5 Posts

    Default

    Well w3schools didnt realy help. Its too complicated.
    Seconed, I just like saying
    Quote Originally Posted by FrickenTrevor View Post
    and discuss.....
    to my posts. Its not homework of any kind.
    I actualy need it for my site.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    Please explain why you want to do this and I'd be happy to give you code for it, I've already written it out, at least as best as I could understand your requirements.

    Did you at least understand my explanation, the difference between subtracting from the date number itself, as opposed to setting the Date Object back? Also, is this even what you are going for? Do you want the result as just a raw number -1 to 29, 1 to 31? Or what exactly? Why?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •