Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert Date (E.g 10/11/2004) to 200405 2

Status
Not open for further replies.

salimwng

IS-IT--Management
Mar 11, 2002
134
MU
Hi,

I need to convert the current date to a format like 200405. That is for whatever date i choose from the DateTimePicker in my Windows Form, it is automatically converted to a format YYYY+YY+1. In other words, if i choose 10/11/2004 my database should record 200405 or if i choose 03/27/2005, the database should record 200506.

I have searched and tried some examples in the previous post here, but could not come across an appropriate one. I am new at VB.Net.

Can anybody help me to solve this please?

Thank you
Salim
 
Hello,

Have you tried the Format function? It takes an expression (in this case a Date) and returns a string in a specified format. So to answer your question, maybe you could try
Code:
 newDate = CInt(Format(myDateTimePicker.Value, "yyyy")) + CInt(Format(myDateTimePicker.Value, "yy")) + 1
 
Code:
newDate = (Year(CDate(myDateTimePicker.Value))) & (Year(CDate(myDateTimePicker.Value.AddYears(1))).ToString.Substring(2, 2))

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Thanks Huel and Christiaan.

Both works great. I give you a start for this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top