Solved

Create a Method to convert dates

Posted on 2006-07-17
3
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

635 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