Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I am having the two date format as below,



C#
var sysdate = new Date();
var eta = "27-01-2013 00:00:00";
var arrivaldate = new Date(eta);


Now im getting sysdate as "Tue Jun 25 17:14:58 UTC+0530 2013" but eta i am getting the value like "Sun Mar 1 00:00:00 UTC+0530 2015" which is wrong. pls help me to solve.
Posted

Hi Dharma M,

Format of the second string is wrong.
Below is the simple way to get it right,

JavaScript
var sysdate = new Date();

var eta = ("27-01-2013").split('-');
var arrivaldate = new Date(eta[2]+'/'+eta[1]+'/'+eta[0]);

alert(sysdate);
alert(arrivaldate);
 
Share this answer
 
Comments
Dharma M 25-Jun-13 10:18am    
the above solution will work if date does not have the time, but i need the form along with time.
Please check my answer "Solution 2".
Problem
Refer - Difference between Date(dateString) and new Date(dateString)[^].
Quote:

new Date(dateString) uses one of these formats:

"October 13, 1975 11:13:00"
"October 13, 1975 11:13"
"October 13, 1975"

Solution
So, you can do like...
JavaScript
var eta = "January 27, 2013 00:00:00";


Demo
[Demo] new Date(dateString) example[^]
 
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