XML Date Time

J

Jeff Uchtman

Not sure if this is the right group. Have a XML wiht date coming in the
following format:
<date_MMDDYYYY>

Have a function pulling numbers

function getDate(d) {
return d.slice(5,7) + '/' + d.slice(7,9) + '/' + d.slice(9);
}

Would like to convert to long date, i.e August 29, 2006.

Any help?
Thanks
Jeff

Thanks
Jeff
 
J

Jon Shemitz

Jeff said:
Not sure if this is the right group. Have a XML wiht date coming in the
following format:
<date_MMDDYYYY>

Have a function pulling numbers

function getDate(d) {
return d.slice(5,7) + '/' + d.slice(7,9) + '/' + d.slice(9);
}

Would like to convert to long date, i.e August 29, 2006.

Look at the DateTime struct. There's a constructor that takes year,
month, day as integers. You can then return the DateTime's
ToString("D"), or ToLongDateString.

Untested code that assumes it has valid input:

function string GetDate(string date_MMDDYYYY)
{
int Year = Convert.ToInt32(date_MMDDYYYY.Substring(9, 4));
int Month = Convert.ToInt32(date_MMDDYYYY.Substring(5, 2));
int Day = Convert.ToInt32(date_MMDDYYYY.Substring(7, 2));
DateTime Date = new DateTime(Year, Month, Day);
return Date.ToLongDateString();
}
 
J

Jeff Uchtman

Perfect! Thanks!

Jeff



Jon Shemitz said:
Look at the DateTime struct. There's a constructor that takes year,
month, day as integers. You can then return the DateTime's
ToString("D"), or ToLongDateString.

Untested code that assumes it has valid input:

function string GetDate(string date_MMDDYYYY)
{
int Year = Convert.ToInt32(date_MMDDYYYY.Substring(9, 4));
int Month = Convert.ToInt32(date_MMDDYYYY.Substring(5, 2));
int Day = Convert.ToInt32(date_MMDDYYYY.Substring(7, 2));
DateTime Date = new DateTime(Year, Month, Day);
return Date.ToLongDateString();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top