0

I have a code in asp.net, where the user enters the date selection throught an AJAX calendar pop-up control as per below:

<td class="style14">
<asp:TextBox ID="DateSelection" runat="server" Height="22px" Width="90px"
AutoPostBack="True"></asp:TextBox>
<asp:ImageButton ID="ImageButtonDateSelection" runat="server" Height="22px" 
ImageUrl="~/Images/Calendar.jpg" Width="19px" />
<asp:CalendarExtender ID="CalendarExtenderDateSelection" runat="server" 
Format="dd/MM/yyyy" PopupButtonID="ImageButtonDateSelection" 
PopupPosition="BottomRight" TargetControlID="DateSelection" 
FirstDayOfWeek="Monday">
</asp:CalendarExtender></td>

From SQL I pickup the date and use it in the SQL code as follows:

declare @dt datetime 
set @dt = convert(datetime,'" & DateSelection.Text & "',104

All is well in my remote desktop, but when I publish the site it doent' work due to diferent date formats on server.

I can not figure out what format the server has, but I'm wondering if there is a fool proof way to work with any date format, so that I can develop on my pc with my date format and send the code safely to the server and warantee that it will work. Thanks.

2 Answers 2

1

First of all you can check what is the dateformat setting for your connecdtion on that server by DBCC USEROPTIONS

DBCC USEROPTIONS

Output:

Set Option  Value
----------------------
...
language    us_english
dateformat  mdy         <---
datefirst   7
...

Second you can change date format for your connection using SET DATEFORMAT

SET DATEFORMAT MDY;

Third and you can always use SQL/ISO date format which is YYYY-MM-DD

DECLARE @dt DATETIME 
SET @dt = CONVERT(DATETIME,'2013-03-09')
Sign up to request clarification or add additional context in comments.

Comments

0

Set the culture property as : - <%@ Page Title="" Language="C#" MasterPageFile="~/User/MainMaster.master" AutoEventWireup="true" CodeFile="MemberRegistration.aspx.cs" Inherits="HO_MemberRegistration" Culture="en-gb" %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.