Click here to Skip to main content
       

JavaScript

 
QuestionHow does Yandex do its trick? PinmemberXarzu14-Nov-12 20:42 
AnswerRe: How does Yandex do its trick? [modified] PinmvpManfred R. Bihy14-Nov-12 21:44 
Questiondisplay record from two different time Pinmemberuti123fil8-Nov-12 18:15 
AnswerRe: display record from two different time PinmvpRichard MacCutchan9-Nov-12 0:47 
QuestionAdding a month to the current date PinmemberSadiqMohammed7-Nov-12 0:48 
AnswerRe: Adding a month to the current date PinmemberRichard Deeming7-Nov-12 3:00 
GeneralRe: Adding a month to the current date PinmemberSadiqMohammed7-Nov-12 19:31 
GeneralRe: Adding a month to the current date PinmemberRichard Deeming8-Nov-12 3:11 
I don't know how you've managed to get 1st April; with the code below, I get 2nd March:
var post_date = new Date(2012, 0, 31);
var expiration_date = new Date(post_date.setMonth(post_date.getMonth() + 1));
expiration_date = expiration_date.getMonth() + 1 + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
alert(expiration_date);
 
The reason it's 2nd March is that there is no 31st February. If you want the expiration_date to always be a date within the following month, you'll need to check that manually:
var post_date = new Date(2012, 0, 31);
 
var firstOfMonth = new Date(post_date);
firstOfMonth.setDate(1);
firstOfMonth.setMonth(post_date.getMonth() + 1);
 
var expiration_date = new Date(firstOfMonth);
expiration_date.setDate(post_date.getDate());
 
while (expiration_date.getMonth() != firstOfMonth.getMonth())
{
    expiration_date.setDate(expiration_date.getDate() - 1);
}
 
expiration_date = expiration_date.getMonth() + 1 + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
alert(expiration_date);
 
Alternatively, you could look at the Datejs library[^].



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Adding a month to the current date PinmemberSadiqMohammed8-Nov-12 20:08 
AnswerRe: Adding a month to the current date Pinmemberdeepak.m.shrma19-Nov-12 19:07 
GeneralRe: Adding a month to the current date PinmemberPeter_in_278019-Nov-12 19:58 
GeneralRe: Adding a month to the current date Pinmemberdeepak.m.shrma19-Nov-12 20:52 
QuestionNeed to pass object value from javascript to php Pinmembergern844-Nov-12 11:08 
SuggestionRe: Need to pass object value from javascript to php Pinmembern.podbielski4-Nov-12 13:56 
GeneralRe: Need to pass object value from javascript to php Pinmembergern844-Nov-12 14:29 
GeneralRe: Need to pass object value from javascript to php Pinmembern.podbielski4-Nov-12 21:48 
GeneralRe: Need to pass object value from javascript to php Pinmemberzengnanhua22-Nov-12 19:27 
GeneralRe: Need to pass object value from javascript to php PinmemberKillzone DeathMan23-Nov-12 0:39 
QuestionWindow restore Pinmembermkotaska1-Nov-12 7:00 
AnswerRe: Window restore Pinmemberryanb312-Nov-12 12:03 
Questionunzip the .gzip files [modified] PinmemberKIDYA31-Oct-12 20:44 
AnswerRe: unzip the .gzip files PinmemberJay Zhu2-Nov-12 18:20 
Questioni have created 3 widgets using jquery ui - header, footer, textarea. i am observing abnormal behavior because of the footer widget. PinmemberAbhishek Prakash30-Oct-12 6:53 
AnswerRe: i have created 3 widgets using jquery ui - header, footer, textarea. i am observing abnormal behavior because of the footer widget. [modified] Pinmembern.podbielski30-Oct-12 22:48 
GeneralRe: i have created 3 widgets using jquery ui - header, footer, textarea. i am observing abnormal behavior because of the footer widget. PinmemberAbhishek Prakash31-Oct-12 0:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 23 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid