Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need code in Calculating Duration Between Two Dates in Years, Months and Days in vb.net and converting 5-14-1991 to may 14,1991
thanks
Posted
Comments
Reiss 5-Oct-11 11:11am    
What have you tried?

1 solution

This as simple as this:

The structure System.DateTime has "-" (subtraction operator) defined; its return type is System.TimeSpan.

See http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

This should be more then enough.

Do not "convert" anything. You need to work with System.DateTime structure, not with string representation of it. You only should create string representation when you show time data on screen. In this case you just need to appropriate format, based on current UI culture of your thread or just custom.

See System.DateTime here: http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].
For formatting, see:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900