?
Solved

format date time into dd-mm-yy

Posted on 2006-03-26
4
Medium Priority
?
1,772 Views
Last Modified: 2008-03-10
How do i format a date time to a string with the foloowing format
mm-dd-yy

01-12-04
0
Comment
Question by:DaFou
  • 3
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16298268
C#:

DateTime d = DateTime.Now;
string s = d.ToString("MM-dd-yy"));
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 16298270
VB:

Dim d as DateTime
Dim s as string

d = DateTime.Now
s = d.ToString("MM-dd-yy"))
0
 
LVL 2

Author Comment

by:DaFou
ID: 16298379
I have a SQLdatareader with a date in it. Somehoe the conversion fails when i try to use this syntax
SomeSqlDataReader("SomeDateField").ToString("dd-MM-yy")

lDR("fld_dt_TransmitDateOut").ToString("dd-MM-yy")      Run-time exception thrown : System.InvalidCastException - Conversion from string "dd-MM-yy" to type 'Integer' is not valid.      
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16298435
DateTime structire doesn't hace ToString(Integer) method. This means that lDR("fld_dt_TransmitDateOut") field type is not DateTime in this case. You need to check what is it's type - maybe null.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

839 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