Solved

Create a Method to convert dates

Posted on 2006-07-17
3
242 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 300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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