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
Solved

format string date

Posted on 2013-02-04
7
381 Views
Last Modified: 2013-02-05
if I have a date string like "01022013" which is january 02, 2013
how can I format it to show jan, 02, 13 or january 02, 2013
0
Comment
Question by:sevensnake77
  • 3
  • 3
7 Comments
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 293 total points
ID: 38852754
DateTime dt = new DateTime(int.Parse(query.Substring(4, 4)), int.Parse(query.Substring(0, 2)), int.Parse(query.Substring(2, 2)));

If you're using VB

int.Parse = Integer.Parse


Constructor for DateTime is (int year, int month, int day);

From there you can do
dt.ToString("<format>");

where format = http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 38852795
I tried that but kept coming up with todays date not the date I specified.

Dim d = DateTime.Now.ToString("MMM d, yyyy")
Response.Write(String.Format(d, "01022013"))
0
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 293 total points
ID: 38852805
Response.Write(DateTime.Now.ToString("MMM d, yyyy"))

If you wanted to use the Variable:

Dim d as DateTime = DateTime.Now (not the format);
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 9

Author Comment

by:sevensnake77
ID: 38852957
give me an example on the current  string i provided up top.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 97 total points
ID: 38852988
C#:

DateTime d;
IFormatProvider provider = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;

if (DateTime.TryParseExact("01022013", "MMddyyyy", provider, DateTimeStyles.None, out d))
{
    string result = d.ToString("MMMM dd, yyyy");
}

Open in new window


VB.NET

Dim d As DateTime
Dim provider As IFormatProvider = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;

If (DateTime.TryParseExact("01022013", "MMddyyyy", provider, DateTimeStyles.None, d))
    Dim result As String= d.ToString("MMMM dd, yyyy");
End If

Open in new window

0
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 293 total points
ID: 38853045
dim dateFormat as string = "MMM d, yyyy"
Response.Write(DateTime.Now.ToString(dateFormat ))


Change your dateFormat to match this:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx 

kaufmed has provided one format for you, but knowing how to control the format is the key.
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 38855230
tks
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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