Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Javascript DateFormat ( 6 month window)

    Hi Guys ,

    i am wondering how i can get the current 6 month windows like the following

    always based onthe current month


    Aug-11
    Sep-11
    Oct-11
    Nov-11
    Dec-11
    Jan-12


    thanks!

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    PHP Code:
    var monthSpan 6;
    var 
    months = ['Jan''Feb''Mar''Apr''May''Jun''Jul''Aug''Sep''Oct''Nov''Dec'];

    var 
    date = new Date();
    date.setDate(1);

    var 
    output "";
    for (var 
    0monthSpani++) {
        
    output += months[date.getMonth()] + '-' + (date.getFullYear() % 100) + '\n';
        
    date.setMonth(date.getMonth() + 1);
    }

    alert(output); 

  • Users who have thanked venegal for this post:

    korssane (08-17-2011)

  • #3
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thank you so much venegal for the help ,

    i will figure out how to assign each month a specific variable...

    thanks again

  • #4
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Do you mind another question. i am stack on something else ..
    iam unable to get the value of a dynamic generated dropdownlist

    i can get it on firefox but not IE..

    any idea ?

    thanks

  • #5
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    For this one, you should probably post your code, so we can see why your method wouldn't work in IE.
    Last edited by venegal; 08-17-2011 at 06:28 PM. Reason: typo

  • #6
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    OK i ll do ,
    thanks budd. i will create a new thread and hope you will see it..lol

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Quote Originally Posted by korssane View Post
    i will figure out how to assign each month a specific variable...
    Don't do it!

    Use an array and assign the months to elements of the array.

    Example, based on Venegal's code:
    Code:
    var monthSpan = 6;
    var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    
    var date = new Date();
    date.setDate(1);
    
    var namedMonths = []; // this is the array of names!
    for (var i = 0; i < monthSpan; i++) {
        namedMonts[i] = months[date.getMonth()] + '-' + (date.getFullYear() % 100);
        date.setMonth(date.getMonth() + 1);
    }
    Now you have a nice array, where namedMonths[0] is the current month and (for example) namedMonths[5] is the sixth month.

    MUCH better than trying to create and use 6 separate variables.

  • #8
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    already did it and it works great

    thanks a bunch guys.

  • #9
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Hi Guys,
    i got another issue when trying to insert those values into oracle db ..
    it seems it does not recognize mmm-yy format

    and gives me ORA-01843: not valid month
    my Oracle field is a date filed type.

    Is there a way to leave the actual format and just create another one with date type ?
    or just give it the 'mm/dd/yyyy' format with mask 'mmm-yy'

    thanks
    Last edited by korssane; 08-19-2011 at 04:58 PM.


  •  

    Posting Permissions

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