Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2009, 02:18 AM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
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
  #2 (permalink)  
Old March 8th, 2009, 03:08 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
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)
  #3 (permalink)  
Old March 8th, 2009, 05:11 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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)
  #4 (permalink)  
Old March 8th, 2009, 02:56 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.