Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create a Method to convert dates

Posted on 2006-07-17
3
Medium Priority
?
256 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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