none
add dates to array variable RRS feed

  • Question

  • Dear all,

    I have a date string is coming in dd-mm-yyyy format.Now i want to increment one by one  to this date and want to push it in array variable.How to achieve this.Please help.thanks in advance.

    Regards,

    Praveen

    Tuesday, June 19, 2018 8:04 PM

Answers

  • Hi,

    Sample code for your reference get current date as "yyyy-mm-dd" format and then increase one day by day in for loop and then push to an array:

        <script type="text/javascript">
            pushtoarr();
            function pushtoarr() {
    
            var arr = [];
            var today = new Date();
            var dd = today.getDate();
            var mm = today.getMonth() + 1; //January is 0!
    
            var yyyy = today.getFullYear();
            if (dd < 10) {
                dd = '0' + dd;
            }
            if (mm < 10) {
                mm = '0' + mm;
            }
                //var today = yyyy + '-' + mm + '-' + dd;
                for (var i = 1; i <= 5; i++)
                {
                    var newdd = dd + i;
                    var date = yyyy + '-' + mm + '-' + newdd;
                    arr.push(date);
                }
                console.log(arr);
            
            }
    
    
        </script>

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by Praveenrangu Thursday, June 21, 2018 12:43 PM
    Thursday, June 21, 2018 2:48 AM

All replies

  • Hi Parveen,

    Which code type you are using ? JavaScript or C# code ? And did you want to add one more day to the date string and then store the date in Array ? 

    Please provide more detailed information about your requirement.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


    Wednesday, June 20, 2018 9:48 AM
  • Thanks jerry for the reply.Iam using javascript code and i have a date variable and i want to increment one more day one by one and i want to store all the dates in a array.
    Wednesday, June 20, 2018 10:35 AM
  • Hi,

    Sample code for your reference get current date as "yyyy-mm-dd" format and then increase one day by day in for loop and then push to an array:

        <script type="text/javascript">
            pushtoarr();
            function pushtoarr() {
    
            var arr = [];
            var today = new Date();
            var dd = today.getDate();
            var mm = today.getMonth() + 1; //January is 0!
    
            var yyyy = today.getFullYear();
            if (dd < 10) {
                dd = '0' + dd;
            }
            if (mm < 10) {
                mm = '0' + mm;
            }
                //var today = yyyy + '-' + mm + '-' + dd;
                for (var i = 1; i <= 5; i++)
                {
                    var newdd = dd + i;
                    var date = yyyy + '-' + mm + '-' + newdd;
                    arr.push(date);
                }
                console.log(arr);
            
            }
    
    
        </script>

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by Praveenrangu Thursday, June 21, 2018 12:43 PM
    Thursday, June 21, 2018 2:48 AM