convert Date

I have a date string in format MM /dd//yyyy and I want to convert a Date object from this string. new Date(yyyy/DD/MM) but it won't work..

Plz find the attachment
prashanth agsoftware engineer Asked:
Who is Participating?
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
0
 
Rainer JeschorCommented:
Hi,
sorry but attachment is missing.
Can you please explain again
- what you have
- what you want to achieve

As far as I understand, you have a string containing a date in the format MM/dd/yyyy
Now you want to convert this string to a variable of type date.
var orgDateString = "3/2/2015";
var dateParts= orgDateString.split("/");
var resultDate = new Date(dateParts[1], dateParts[0] - 1, dateParts[2]);

Open in new window


HTH
Rainer
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
if you use jquery, you may want to look into some date plug-ins, it'll make things a lot easier:

https://github.com/phstc/jquery-dateFormat
http://plugins.jquery.com/formatDateTime/
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
prashanth agsoftware engineer Author Commented:
I have a date string in format MM /dd//yyyy and I want to convert a Date object from this string. new Date(yyyy/DD/MM) but it won't work..

function verify(isField)
{
     splitDate = isField.value.split("/");
var dYear = splitdate[0],
var dDay = splitdate[1],
var dMonth = splitdate[2]

refDate = new Date(dYear+"/"+dMonth+"/"+dDay);
if (dMonth < 1 || dMonth > 12 || dYear.length != 4 || (!/^19|20/.test(dYear))){return false}
nDay[i++] = dDay;

//alert(refDate);
return refDate;  
  }
   
function holidays(dStart,dEnd){

        t = 0;
        for (i=0; i<skipDate.length; i++)
            {
       
             refDate = new Date(tmp[0]+"/"+tmp[1]+"/"+tmp[2]);
//alert(refDate);
             if (refDate >= dStart && refDate <= dEnd)
                {t++}
            }
        return t;
    }
}
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try this then:

function verify(isField)
{
return isField.getMonth() + 1) + '/' + isField.getDate() + '/' +  isField.getFullYear();  
  }

Open in new window

0
 
prashanth agsoftware engineer Author Commented:
Hi ,
I change code as you mention  but it won't  work
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
what doesnt work? you get an error? nothing happens? be more specific
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.