SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Riding the electron wave
    0 Post(s)
    0 Thread(s)

    Rewriting this PHP script in Javascript, How?

    I wrote this script some time ago as a small program to help me figure out how many business days from now is n.

    I need to change it now because I don't want to do a whole page reload to get the answer. I don't want the server working that much. So how can I rewrite this script in javascript, so that the result can be found without a page request?

    If someone can point me in the right direction, I would really appreciate it.

    PHP Code:
    if ( $numDays $_POST['numDays'] ) {
    $futureDate = ( $numDays 86400 ) + time();
    $futureDate    date "w"$futureDate ); // 'w' = numeric representation of days of week
    if ( == $futureDate )         // 6 = Saturday
    $futureDate += 172800;     // # of seconds in 2 days
    else if ( == $futureDate )         // 0 = Sunday
    $futureDate += 86400;     // # of seconds in 1 day
    $newDate "<p><strong>$numDays</strong> days from now is:<br />
    date "D, M j, Y"$futureDate ) . "</strong></p>";
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."

  2. #2
    SitePoint Enthusiast Tygatur's Avatar
    Join Date
    Apr 2006
    0 Post(s)
    0 Thread(s)
    There is no tool to do this and for practise i wrote this script for you.

    HTML Code:
    <script type="text/javascript">/*<![CDATA[*/
    function timetogo(moredays){
    now=new Date();
    then=new Date(now.getTime()+moredays*86400000);
    alert(typeof then);
    alert('The date of '+moredays+' in the future is '+then);
    I hope it works the same way your PHP Scripts does. It is not a translation of your script because the Date object in JavaScript is very different to the Date object in PHP.
    to code or not to code ?
    that's too much of a question for a signature.


Posting Permissions

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