Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create a Method to convert dates

Posted on 2006-07-17
3
Medium Priority
?
263 Views
Last Modified: 2010-04-16
Hi there,

I have multiple fields that I will want to convert to a specific date format but I don't want to have to retype all of the code over and over so I'd like to create a Method that I can pass the field into which would convert it.

Right now I have

string strDate = line.Substring(296,8);
DateTime MyDate = DateTime.ParseExact(strDate,"yyyyMMdd",CultureInfo.CurrentCulture);
polDS.Policy[0].DEPARTUREDATE = MyDate.ToString("MM/dd/yyyy");

Is there a way to create a method that I could pass in strDate so that it's converted? That way I can just call the method for each substring that I need converted.

ConvertDate(line.Substring(296,8);

Thank you


0
Comment
Question by:boukaka
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 1200 total points
ID: 17123132
Hi boukaka,

public DateTime convertDate( string strDate )
{
  DateTime MyDate = DateTime.ParseExact(strDate,"yyyyMMdd",CultureInfo.CurrentCulture);
  return MyDate;
}

then just call it like this:

string strDate = line.Substring(296,8);
DateTime MyDate = convertDate( strDate );

Apresto
0
 
LVL 23

Expert Comment

by:apresto
ID: 17123134
is this what you meant?
0
 

Author Comment

by:boukaka
ID: 17123698
That's exactly what I meant! Thank you - sorry for the delay, went for lunch.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Integration Management Part 2

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question