/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Month start and EndDate

Hi all,
How can I find the current month start and enddate

Thanks in advance
Dana

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@mrhooApr 30.2008 — [CODE]function monthrange(){
var D= new Date(new Date().setDate(1));
var d1= D.toLocaleDateString();
D.setMonth(D.getMonth()+1);
var d2= new Date(D.setDate(D.getDate()-1));
return [d1,d2.toLocaleDateString()];
}[/CODE]
Copy linkTweet thisAlerts:
@KorApr 30.2008 — <i>
</i>function currentMonthEnds(){
var startD=new Date();
var endD=new Date();
var m=startD.getMonth();//current month
startD.setDate(1);//current month start date as object
var i=27;
while(endD.getMonth()==m){
i++;endD.setDate(i);
}
endD.setDate(0);//current month end date as object
return [startD,endD]
}
Copy linkTweet thisAlerts:
@danasegaraneauthorApr 30.2008 — Thank you very much..

How can Format the function as dd/mm/yyyy

if i pass the argument as

function currentMonthEnds([B]format[/B]){

var startD=new Date();

var endD=new Date();

var m=startD.getMonth();//current month

startD.setDate(1);//current month start date as object

var i=27;

while(endD.getMonth()==m){

i++;endD.setDate(i);

}

endD.setDate(0);//current month end date as object

return [startD,endD]

}
Copy linkTweet thisAlerts:
@KorApr 30.2008 — Here you are (I have also simplified the code):
<i>
</i>&lt;script type="text/javascript"&gt;
function monthEnds(date){//as "dd/mm/yyyy"
d=date.split('/');
var startD=new Date(Number(d[2]),Number(d[1])-1,Number(d[0]));
var endD=new Date(Number(d[2]),Number(d[1])-1,Number(d[0]));
var m=startD.getMonth();//current month
startD.setDate(1);//current month start date as object
endD.setMonth(m+1);
endD.setDate(0);//current month end date as object
return [startD,endD]
}
onload=function(){
var date= monthEnds('05/02/2008');
alert(date[0]);
alert(date[1])
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@danasegaraneauthorApr 30.2008 — Thank you very much
Copy linkTweet thisAlerts:
@danasegaraneauthorMay 05.2008 — Hi mrhoo & Kor,

Can I able to pass the format and get the formated values instead of hard coding the date format ?
×

Success!

Help @danasegarane spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...