• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 143
  • Last Modified:

Convert date format

How can I convert a string (date) to this format ("MM/dd/yyyy")?
3/1/2015 or 3/12/2015
0
VBdotnet2005
Asked:
VBdotnet2005
1 Solution
 
sirbountyCommented:
myDate = today.tostring("MM/dd/yyyy")
0
 
VBdotnet2005Author Commented:
Is your sample just convert today to a string format?
0
 
ElrondCTCommented:
I'm not sure what kind of conversion you want to do. Is the input string in a different form, like "March 1, 2015"? Should the output be a string or a date type? Do you need to worry about alternate date formats (European dd/mm/yyyy, etc.)?

You may want to look at the Date.Parse method, depending on exactly what you want to do.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Lokesh B RDeveloperCommented:
string date = DateTime.Now.ToString("MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);

Open in new window

0
 
Kaushal AroraTechnical AnalystCommented:
Dear VBdotnet2005,

Kindly go through these links:

https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx
http://net-informations.com/q/faq/stringdate.html
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Hope these help you in solving your problem.

Regards
Kaushal Arora
0
 
Gustav BrockCIOCommented:
If your "date" is a string, you need to parse it first:
Dim TxtDate As String
Dim DatDate As Date
Dim MyDate As String

TxtDate = "3/12/2015"

DatDate = DateTime.Parse(TxtDate, System.Globalization.CultureInfo.InvariantCulture)

MyDate = DatDate.ToString("MM'/'dd'/'yyyy")
Console.Writeline(MyDate)

' Or in one line, should you prefer:
MyDate = DateTime.Parse(TxtDate, System.Globalization.CultureInfo.InvariantCulture).ToString("MM'/'dd'/'yyyy")
Console.Writeline(MyDate)

Open in new window

/gustav
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now