Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

format string date

Posted on 2013-02-04
7
Medium Priority
?
385 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:Seven price
[X]
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
  • 3
  • 3
7 Comments
 
LVL 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 1172 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:Seven price
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 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 1172 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 9

Author Comment

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

Accepted Solution

by:
käµfm³d   👽 earned 388 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 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 1172 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:Seven price
ID: 38855230
tks
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 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