Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8454553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:03:30+00:00 2026-06-10T12:03:30+00:00

I have a script that is used for adding or subtracting a number of

  • 0

I have a script that is used for adding or subtracting a number of days to some dates.

for example if I have a date that is 10/08/2012 And I do +5 it should return 15/08/2012

If we are the end of the month it should return the next month.

Actually this script seems to be good, but the thing is the date format. It returns something like a timestamp and I don’t really know how to format it, because javascript is not so easy for me I’ve tried to find to do something like in php date('d-m-y', strtotime($row['date'])
But I did not find the equivalent for javascript.

First of all here comes the code I used to have all dates.

<?php $jours=d ate( 'Y-m-d'); $sql="SELECT * FROM agenda WHERE n_doss='"
.mysql_real_escape_string($_GET[ 'n_doss']). "' AND qualite='".mysql_real_escape_string($_GET[
'qualite']). "' AND liasse='".$_GET[ 'liasse']. "'"; $qry=m ysql_query($sql) or
die(__LINE__.mysql_error().$sql); $i=- 1; // index des enregistrements
?>
    <form action="<?php echo (isset($_POST['go'])) ? 'go2.php' : '#'; ?>"
    method="post">
        <input type="hidden" name="liasse" value="<?php echo $_GET['liasse']; ?>"
        />
        <input type="hidden" name="n_doss" value="<?php echo $_GET['n_doss']; ?>"
        />
        <table id="box-table-a">
            <tr>
                <th scope="col">
                    <input name="data[<?php echo ++$i; ?>][code_s]" type="text" value="CODE S"
                    size="10">
                </th>
                <th scope="col">
                    <input name="data[<?php echo $i; ?>][libelle]" type="text" value="LIBELLE"
                    size="30">
                </th>
                <th scope="col">
                    <input name="data[<?php echo $i; ?>][action]" type="text" value="ACTION"
                    size="15">
                </th>
                <th scope="col">
                    <input name="data[<?php echo $i; ?>][libelle]" type="text" value="DESCRIPTION"
                    size="40">
                </th>
                <th scope="col">
                    <input type="text" name="data[<?php echo $i; ?>][date]" value="DATE D'ACTION"
                    size="12">
                </th>
                <th scope="col">
                    <input type="text" name="data[<?php echo $i; ?>][date]" value="VALIDATION"
                    size="12">
                </th>
                <th scope="col"><strong>ETAT</strong>
                </th>
            </tr>
            <?php while($row=m ysql_fetch_assoc($qry)): ?>
                <tr>
                    <td>
                        <input name="data[<?php echo ++$i; ?>][code_s]" type="text" value="<?php echo $row['code_s'];?>"
                        size="10">
                    </td>
                    <td>
                        <input name="data[<?php echo $i; ?>][libelle]" type="text" value="<?php echo $row['libelle']; ?>"
                        size="30">
                    </td>
                    <td>
                        <input name="data[<?php echo $i; ?>][action]" type="text" value="<?php echo $row['action']; ?>"
                        size="15">
                    </td>
                    <td>
                        <input name="data[<?php echo $i; ?>][libelle]" type="text" value="<?php echo $row['description']; ?>"
                        size="40">
                    </td>
                    <td>
                        <input type="text" name="data[<?php echo $i; ?>][date]" class="date" id="date<?php echo $i; ?>"
                        value="<?php 


echo date('d-m-Y',strtotime($row['date_action'])) ;

 ?>" size="12">
                    </td>
                    <td nowrap>
                        <input type="text" name="data[<?php echo $i; ?>][date_validation]" id="data[<?php echo $i; ?>][date_validation]"
                        value="<?php if($row['date_validation']=='0000-00-00') {echo 'Non trait&eacute;' ; }
 else {
echo (date('d-m-Y',strtotime($row['date_validation']))); }
 ?>" size="12">
                    </td>
                    <td nowrap>
                        <?php if($row[ 'date_validation']=='0000-00-00' AND strtotime($row[
                        'date_action'])>strtotime(date('Y-m-d'))) {?><a href="edit-action.php?id=<?php echo $row['id'] ; ?>&n_doss=<?php echo $row['n_doss'] ; ?>&liasse=<?php echo $_GET['liasse'] ?>&qualite=<?php echo $_GET['qualite'] ?>"><img src="images/gtk-edit.png" width="24" height="24"></a> 
                            <a
                            href="validate-action.php?id=<?php echo $row['id'] ; ?>&n_doss=<?php echo $row['n_doss'] ; ?>&liasse=<?php echo $_GET['liasse'] ?>&qualite=<?php echo $_GET['qualite'] ?>">
                                <img src="images/go.gif" width="24" height="24">
                                </a> <a href="delete-action.php?id=<?php echo $row['id'] ; ?>&n_doss=<?php echo $row['n_doss'] ; ?>&liasse=<?php echo $_GET['liasse'] ?>"
                                onClick="return confirm('voulez vous vraiment supprimer cette action ?')"><img src="images/trash-paper.png" width="24" height="24"></a>
                                <?php
                                } elseif($row[ 'date_validation']=='0000-00-00' AND strtotime($row[
                                'date_action'])<=strtotime(date( 'Y-m-d'))) {?><a href="#" onClick="return confirm('Vous ne pouvez pas &eacute;diter ou changer la date d\'une action appartenant à votre passif !')"><img src="images/gtk-edit.png" width="24" height="24"></a> 
                                    <a
                                    href="validate-action.php?id=<?php echo $row['id'] ; ?>&n_doss=<?php echo $row['n_doss'] ; ?>&liasse=<?php echo $_GET['liasse'] ?>&qualite=<?php echo $_GET['qualite'] ?>">
                                        <img src="images/go.gif" width="24" height="24">
                                        </a> <a href="#" onClick="return confirm('Vous ne pouvez pas supprimer une action appartenant à votre passif !')"><img src="images/trash-paper.png" width="24" height="24"></a>
                                        <?php
                                        } else { ?>
                                            <img src="images/tick_48.png" width="24" height="24">
                                            <?php } ?>
                    </td>
                </tr>
                <?php endwhile; ?>
                    </td>
                    </tr>
        </table>

Here is the form I use for adding days (the form for subtracting days is not done because I yet meet some trouble with the function for adding days.

<table width="50%">
    <tr>
        <td>
            <div class="info"> <strong>Décalage des date </strong>

                <table width="150" border="0" cellspacing="0"
                cellpadding="0">
                    <tr>
                        <td align="center" bgcolor="#FFFF99">
                            <input type="image" src="images/minus_remove_green.png" width="22" height="22"
                            name="submit" value="moins" />
                            <input name="jours" type="text" value="" size="5" id="nb" />
                            <input type="image" src="images/plus_add_green.png" width="22" height="22"
                            onClick="addday()" />
                        </td>
                    </tr>
                </table>Ajouter une action <a href="add-action.php?n_doss=<?php echo $_GET['n_doss'] ; ?>&liasse=<?php echo $_GET['liasse'] ?>&amp;qualite=<?php echo $_GET['qualite'] ; ?>"><img src="images/plus.png" width="24" height="24" border="0"></a>

            </div>
        </td>
    </tr>
</table>

And finally I have this javascript that I’ve done:

<script type="text/javascript">
    function addday() {
        var items = new Array();
        var itemCount = document.getElementsByClassName("date");

        for (var i = 0; i < itemCount.length; i++) {
            items[i] = document.getElementById("date" + (i + 1)).value;
        }

        for (var i = 0; i < itemCount.length; i++) {
            items[i] = document.getElementById("date" + (i + 1)).value;
            var itemDtParts = items[i].split("-");
            var itemDt = new Date(itemDtParts[2], itemDtParts[1] - 1, itemDtParts[0]);
            nb = document.getElementById('nb').value;


        var newDate = itemDt.getDate() + nb;
        itemDt.setDate(newDate ) ;
        itemCount[i].value = itemDt;
        }

        return items;
    }
</script>​

The thing is that instead of returning good dates it return something weird like that.

Mon Apr 29 2013 00:00:00 GMT+0200 (Paris, Madrid (heure d’été))

I don’t know how to return a format like that dd-mm-yyyy

I’m really lost.

I’ve tried to do that to format itemCount[i].value = itemDt.format(“dd-mm-yyyy”);

But it returns mistakes saying that date.format is not acceptable for data objects or something like that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:03:31+00:00Added an answer on June 10, 2026 at 12:03 pm

    If you want to return a nice string with a custom format you will probably be better doing it by hand :

    • Use .getDate() to find the day in the month.
    • Use .getMonth() to find the month’s number.
    • Use .getFullYear() to find the year with 4 digits.
    • Add it all in a string.

    Now, you declared itemDt = new Date(...) which is fine, but then all you need to do is something like this :

    itemDt.setDate(itemDt.getDate()+5)
    

    The Date object will handle months/years itself.

    You can use previously stated functions to format your string with something like this :

    return itemDt.getDate()+"/"+itemDt.getMonth()+"/"+itemDt.getFullYear() // 15/08/2012
    

    EDIT:

    Code above will return 15/8/2012 without zero padding.

    return (new Array(2 + 1 - itemDt.getDate().toString().length)).join('0') + itemDt.getDate() + "/" + (new Array(2 + 1 - itemDt.getMonth().toString().length)).join('0') + itemDt.getMonth() + "/" +itemDt.getFullYear();
    // returns zero padded dates 09/07/2012
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tweaked this script that I used from JqueryUi and I have a problem.
I have a function in java script, that I used it to take the
I have a usercontrol that can be used in for example a gridview itemtemplate,
I have some JavaScript that is being used to open a new window and
I have following script that is used to check if file exists in remote
I have a php script that is reading a remote CSV file, and adding
We have a series of scripts that are used when building Apache. Specifically these
I have script that reads remote file content and writes it to local server.
I have this script that run to fix my menu bar to the browser
I have a script that recursively loops through all the sub directories and compresses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.