SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello ALL!

    If today is March 27, 2001. How do I add 2 or 4 or more days to the date to show on screen (ie on the web page) as:

    March 29, 2001
    March 31, 2001

    Would I use JS or Perl or CGI etc? What is the code?
    Thank you for your time!
    Marc

  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    reman...these URL's looks like they contain the info you are looking for, they are all done in Javascript:

    http://developer.netscape.com/viewso...ateobject.html

    http://www.geocities.com/SiliconValley/7116/date.htm

    http://www.codeave.com/javascript/date-time.html

    http://www.research.umbc.edu/~nohe/I...ript/date.html (view source on this one)

    http://www.javascript-page.com/jdate.html

    http://www.merlyn.demon.co.uk/js-dates.htm


    In addition, here is a search query string from google.com:
    http://www.google.com/search?q=javascript%2C+date


    Just a note, the drawback to Javascript for date formatting is that it pulls the date from the Users system, not the server. SO if someone from the other side of the dateline viewed your page, the results might not jibe. A better method might be to use a server side script ie: PHP, ASP or Cold Fusion.

    Anyway, these should at least get you started.
    Last edited by creole; Mar 27, 2001 at 16:40.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the links!

    Originally posted by creole

    In addition, here is a search query string from google.com:
    http://www.google.com/search?q=javascript%2C+date
    Google is the best!


    Just a note, the drawback to Javascript for date formatting is that it pulls the date from the Users system, not the server. SO if someone from the other side of the dateline viewed your page, the results might not jibe. A better method might be to use a server side script ie: PHP, ASP or Cold Fusion.
    Good point! I do not think it matters for the project I am doing...The user fills out a form and that is then made into a coupon.
    Last edited by reman; Mar 28, 2001 at 08:35.
    Thank you for your time!
    Marc

  4. #4
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay...

    The http://www.merlyn.demon.co.uk/js-dates.htm site has an example of Incrementing/Decrementing dates BUT I do not understand how to use it.

    When incrementing and decrementing, remember to allow for possible Summer Time and Time Zone changes. If days are specified, then work directly with Days, rather than milliseconds from 1970, because civil days are not always 86400 seconds.
    with (T = new Date()) setDate(getDate()+1)
    gives this time tomorrow; as usual, month and year will be changed if necessary.
    I am using the following code:
    <SCRIPT language=Javascript>
    <!-- Begin
    theDate= new Date();
    var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
    var day = theDate.getDate();
    var textdate = 0;
    if (theDate.getYear() < 2000)
    textdate = 1900;
    textdate = months[theDate.getMonth()] + ' ' + day + ', ' + (theDate.getYear() + textdate);
    document.write(textdate);
    //-->
    </SCRIPT>
    Last edited by reman; Mar 28, 2001 at 08:34.
    Thank you for your time!
    Marc

  5. #5
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well...I solved it! here is the code. Can it be made smaller?

    <SCRIPT language=Javascript>
    <!-- Begin
    var dayName, monthName, yearName;
    theDate= new Date();
    dayName = parseInt(theDate.getDate() + 5);
    monthName = parseInt(theDate.getMonth());
    yearName = parseInt(theDate.getYear());

    theDate = new Date(yearName, monthName, dayName)
    var daysOfWeek = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
    var day = theDate.getDate();
    var textdate = 0;
    textdate = '<b>'
    + daysOfWeek[theDate.getDate()]
    + ', '
    + months[theDate.getMonth()]
    + ' '
    + day
    + ', '
    + (theDate.getYear() + textdate)
    + '.'
    + '</b>';
    document.write(textdate);
    //-->
    </SCRIPT>
    Last edited by reman; Mar 29, 2001 at 14:40.
    Thank you for your time!
    Marc


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
  •