Solved

DateTime in US format

Posted on 2006-06-16
5
416 Views
Last Modified: 2009-12-16
Hi,

How do you convert a datetime format from one format to any other.  In particular, US to UK format?  I am using sql convert(datetime, '12/05/2006',103) when using dates in sql, but when a date is in US format it causes a problem.  I am using a calendar control, perhaps there is another way around this, such as forcing the control to use a specific locale?

Thanks.
0
Comment
Question by:jasoncpp
[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
  • 4
5 Comments
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16925310
using System.Globalization;
-------------------------------------------
System.DateTime a=System.DateTime.Now;
DateTimePickerFormat  nfi = new CultureInfo( "en-UK", true ).DateTimeFormat;
0
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 500 total points
ID: 16925343
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="en-US"/>

add this line in web.config
or
      System.DateTime a=System.DateTime.Now;
      DateTimeFormatInfo nfi = new CultureInfo( "en-US", true ).DateTimeFormat;
      MessageBox.Show(a.ToString(nfi));
            
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16926021
Hi,
First convert the string to DateTime format
Construct new Sql DateTime parameter and assign the converted datetime value to it.
Pass it to stored procedure.

string intSaleDate =txtSaleDate.Text;      // this is where the problem starts
                              
DateTime a;
a=DateTime.Parse(intSaleDate);
SqlCommand cmdObj = new SqlCommand("MLS_GetData", connObj);
cmdObj.CommandType = CommandType.StoredProcedure;


if (txtSaleDate.Text != "") ///////////// here is the FROM date //////////////
{
    SqlParameter var1=  new SqlParameter("@intSaleDate",SqlDbType.DateTime);
    var1.Value=a ;
      cmdObj.Parameters.Add(var1);
}


Regards
Pradeep

0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16926022
sorry the final one is wrong post
0
 

Author Comment

by:jasoncpp
ID: 16926357
Couple of extra questions, if you don't mind - thanks for good answer.

1. does the below line web.config guarantee that all posted data will be converted to the specified culture.  Can I ensure, for example, all data posted through a calendar picker will be in a certain date format? It appears to do this, as DateTime.Now returns the date format specified in web.config

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB" uiCulture="en-GB"/>

2. Is there a way of returning a DateTimeFormatInfo object for the current machine/server, assuming the above line is not in web.config?

  System.DateTime a=System.DateTime.Now;
     DateTimeFormatInfo nfi = new CultureInfo( "en-US", true ).DateTimeFormat;
     MessageBox.Show(a.ToString(nfi));

Thanks.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

624 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