473,388 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

String to datetime problem

Sl1ver
196 100+
i've got a string like

"May 21 2011"

how do i get it in the yyyy/mm/dd format

i've tried

Expand|Select|Wrap|Line Numbers
  1. public DateTime dt;
  2.  
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         string date = Request.QueryString["date"];
  6.  
  7.         dt = new DateTime();
  8.         dt = DateTime.ParseExact(date, "MM-dd-yyyy", null);
  9.  
  10.     }
  11.  
And i looked on google for ages but I didn't find anything.

Please help
Jul 1 '11 #1
2 2056
GaryTexmo
1,501 Expert 1GB
Have a look at this page: http://www.csharp-examples.net/string-format-datetime/

These are the C# date/time format codes and you can use these to parse your data. Here's a sample I made based on what you've said you're looking for...

Expand|Select|Wrap|Line Numbers
  1. string dateStr = "May 21 2011";
  2. DateTime dt = DateTime.ParseExact(dateStr, "MMMM dd yyyy", null);
  3. MessageBox.Show(dt.ToString("yyyy/MM/dd"));
Jul 1 '11 #2
Sl1ver
196 100+
Hahaha....Works perfectly. Thank for your help
Jul 1 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ramarnath | last post by:
Problem in sending datatime format to the .net webservice from php. description follows. I've created a .net webservice. ..Net Webservice: <WebMethod()> _ Public Function HelloDate(ByVal...
5
by: niju | last post by:
Hi there I am trying to get a single digit hour in 12-hour format with the following code. DateTime hr = DateTime.Now; string hour = hr.ToString("h"); However, I get "Input string was not in...
2
by: Lee | last post by:
Hello all, I'm trying to solve a problem with a string to datetime conversion. The problem arises when I try to convert a string from an XML doc into a .net DateTime. I'm manually creating a...
4
by: luckyabhishek | last post by:
Hi I am using a java webservice in a .NET application. The xml type of a field in this webservice is xsd:datetime. When i call the webservice from the application i get a deserialization error on...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
0
by: Chia Lee Lee | last post by:
Hi, I try to bind records into datagrid based on certain condition.The condition is when the Rdate in database column is larger than today date will be display on datagrid. my problem is , the...
1
by: David C | last post by:
I have an asp.net page that is adding a javascript onclick event by adding an attribute (see below). The problem is that when the file name (shown as strNewFile) has a single quote in the name...
2
by: joasi | last post by:
Hi, I am working in C# with an Object / Relational Database mapping framework, where I want to generate method calls based on string representation of the call signature. I have used reflection and...
11
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I have a SQL database table with rows in which the primary key is a DateTime type (although I don't use the Time part). Have added numerous rows and now want to delete one so I enter the date...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.