Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
var CurDate = "2011.20.11";
var CDate = new Date(CurDate);

i have also try var CDate = (new Date(CurDate)).format("yyyy.dd.mm");
also Date.format("yyyy.dd.mm") but nothing work..
When i use Cdate it will return error as invaliddate().

please help me in this...

Regards,
Jatin
Posted
Updated 23-Aug-20 7:05am
v2

use Date.parseDate(dateValue,format) method.

C#
var d = Date.parseDate("2005-10-05 12:13 am", "Y-m-d g:i a");
document.write(d + "\n");
var d = Date.parseDate("9/5/05", "n/j/y");
document.write(d + "\n");
 
Share this answer
 
Comments
jatinchandarana 25-Apr-11 13:25pm    
Not Working....
When i write var d= Date.parseDate("2011.11.02","yyyy.mm.dd");
it gives me this error
TypeError: Date.parseDate is not a function
Wonde Tadesse 6-Dec-11 10:22am    
Just refer the following date format options.
http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3
This[^] could help.
 
Share this answer
 
Add these two script file in your page
if you don't have these Script plugin then go through these link and download it first.
@download[^]
JavaScript



And try like this it will work 100%

JavaScript
 <script language="javascript" type="text/javascript" src="~/Scripts/date.js"></script>
    <script language="javascript" type="text/javascript" src="~/Scripts/time.js"></script>


var today = Date.today();
        $('#EndDateConsumption').val(today.toString("MM/dd/yyyy"));
        var $startDate = $('#EndDateConsumption');
        var $endDate = $('#StartDateConsumption');
        var dStartDate = Date.parseExact($startDate.val(), "MM/dd/yyyy");
        var prevDate = dStartDate.add(-1).months();
        $endDate.val(prevDate.toString("MM/dd/yyyy"));


Enjoy :)
 
Share this answer
 
v2

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