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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 MontyWeb Ninja at largeCommented:
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
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 Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Big MontyWeb Ninja at largeCommented:
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 MontyWeb Ninja at largeCommented:
what doesnt work? you get an error? nothing happens? be more specific
0
Big MontyWeb Ninja at largeCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.