Click here to Skip to main content
16,004,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Need to get last date of the month using jquery. Currently I have 1st day of the current month...Little help please with
JavaScript
var lastDay=


C#
var dateObj = new Date();
    var firstDay=(date.getDate(),1)   + '/' + (date.getMonth() + 1) + '/' +  date.getFullYear();
    var lastDay=(date.getDate())   + '/' + (date.getMonth()+1) + '/' +  date.getFullYear();
Posted

Solution


First get the Date and then try with Slashes for formatting.

Code


JavaScript
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

var lastDayWithSlashes = (lastDay.getDate()) + '/' + (lastDay.getMonth() + 1) + '/' + lastDay.getFullYear();

alert(lastDayWithSlashes);

Demo


[Demo] Get last date of the current month in jQuery[^]
 
Share this answer
 
Comments
Anele Ngqandu 17-Feb-15 6:34am    
You the bows!
Thanks. :) Keep coding.
Quote:
Currently I have 1st day of the current month
So you can have the 1st day of the next month too...Now take a day away and voila! you have the last day of the current month...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900