Solved

format string date

Posted on 2013-02-04
7
374 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 39

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 293 total points
Comment Utility
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
Comment Utility
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 39

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 293 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
give me an example on the current  string i provided up top.
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 97 total points
Comment Utility
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 39

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 293 total points
Comment Utility
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
Comment Utility
tks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now