Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2009, 02:18 AM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default How to change DateTime to U.S format?

Hi

My format is set to Canadian format but the calendar control I am using sets it to American format. I could probably change the calender control but when I launch my site. The hosting company most likely will have it in U.S format.

So is there a way I can just set my website to just do U.S format?

Like something I just stick in the web.config file or something like that.

Also how do I change my sql server to do U.S format as well.

Thanks
 
Old March 8th, 2009, 03:08 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

SQL Server: You can prefix any query with
SET DATEFORMAT MDY;
SQL Server accepts MDY, DMY, YMD (and even YDM though why I dunno).

Note that you only need to do this once per open connection, so if you execute multiple queries on the same connection, you only need this once. But it won't hurt to do it with each query. You can also change the installation default, but I dunno if you can change the default on a per-user basis.

Might I suggest you find a calendar control that isn't so braindead that it can't allow you to choose your preferred format? If you are talking about a "popup" or "popon" calendar written mostly in JavaScript, I've got one that not only allows you to specify the date format but even allows you to specify which day of the week to start on. 100% HTML and JS, no ASP.NET code needed/wanted.
The Following User Says Thank You to Old Pedant For This Useful Post:
chobo2 (March 8th, 2009)
 
Old March 8th, 2009, 05:11 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can set the culture and uiCulture properties of the Globalization element in web.config:

http://msdn.microsoft.com/en-us/library/hy4kkhe0.aspx

Once you do that, dates, numbers and other presentational elements will adapt to the culture you set. If you set it to auto, it'll adapt to the user's preferred "accept language"...

Quote:
Might I suggest you find a calendar control that isn't so braindead that it can't allow you to choose your preferred format?
Who says the calendar he's using is braindead? The OP is just asking *how* to change it.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
chobo2 (March 8th, 2009)
 
Old March 8th, 2009, 02:56 PM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Old Pedant View Post
SQL Server: You can prefix any query with
SET DATEFORMAT MDY;
SQL Server accepts MDY, DMY, YMD (and even YDM though why I dunno).

Note that you only need to do this once per open connection, so if you execute multiple queries on the same connection, you only need this once. But it won't hurt to do it with each query. You can also change the installation default, but I dunno if you can change the default on a per-user basis.

Might I suggest you find a calendar control that isn't so braindead that it can't allow you to choose your preferred format? If you are talking about a "popup" or "popon" calendar written mostly in JavaScript, I've got one that not only allows you to specify the date format but even allows you to specify which day of the week to start on. 100% HTML and JS, no ASP.NET code needed/wanted.
Well you can send it to me I like to see it. I am using the jquery one and you can change the format of how the date is formated but I just would think it might be more trouble then it is worth.

Like when I go live I am pretty sure my hosting company will have sql and stuff set as U.S so it probably more hassle to get them to change it then it is worth.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert DateTime Format dnyanubhamare C# 2005 2 February 25th, 2008 09:06 AM
hi! datetime format question.. xkorakidis JSP Basics 0 January 10th, 2008 06:17 AM
Datagrid / DateTime Format Setting tanakrita ASP.NET 1.0 and 1.1 Basics 2 May 17th, 2007 09:56 PM
Format datetime deb1980 ASP.NET 2.0 Basics 7 April 17th, 2007 12:35 AM
DateTime format quirks ADMystery ASP.NET 1.0 and 1.1 Professional 5 September 18th, 2006 06:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.