.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Santhakumar Munuswamy
Fauzul Azmi
Post New Web Links

Problem with date variables!!

Posted By:      Posted Date: October 23, 2010    Points: 0   Category :ASP.Net

the asp code for the first txtdateFROM is:

<asp:TextBox ID="txtpubdate" runat="server" MaxLength="1" style="text-align:justify" ValidationGroup="MKE" ></asp:TextBox>
 <asp:ImageButton ID="ImgBntCalcto" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" CausesValidation="true" />
        <ajaxToolkit:MaskedEditExtender ID="MaskedEditcalendar" runat="server"
            ErrorTooltipEnabled="True" />
        <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator" runat="server"
            EmptyValueMessage="Date is required"
            InvalidValueMessage="Date is invalid"

View Complete Post

More Related Resource Links

DataContractJsonSerializer: Problem when deserializing the Date

Sorry for cross-posting. I posted the same question on the Silverlight forum, but it has not received a single answer yet. The majority of folks there must be more interested in UI than in more fundamental stuff.     Hello everyone! Let's say we have the folllowing POCO classes: public class PocoObject : List<PocoPropertyData> {     public PocoObject() {}     public override string ToString()     {         var parts = new List<string>();         foreach (var pd in this)             parts.Add(string.Format("{{N=[{0}], Type=[{1}], V=[{2}]}}", pd.N, pd.V == null ? typeof(object) : pd.V.GetType(),  pd.V));         return string.Join(",", parts);     } } public class PocoPropertyData {     public string N { get; set; }  // the property name     public object V { get; set; }  // the property value } As you can see, the PocoPropertyData can hold value of any type. When I execute the following code in both .NET 4 application and Silverlight 4 application: ========================================================= var poco = new PocoObject {       { new PocoPropertyData { N = "DateTimeField", V =  Da

Problem casting date

I'm developing a Windows Forms app using VS 2008 with a SQL Server 2005 database. I've got search form where users can search for data by entering one or two criteria. One of these is a date which corresponds to a date field in my database. The user clicks on a button, which feeds the criteria into a stored procedure. The results are displayed in a datagridview control. While the functionality works well with the non-date criteria, whenever a date criteria is used on it's own a cast error is raised ('Conversion failed when converting datetime from character string.') I've tried lots of ways of casting the date (formatting using left, right and mid finctions, using the substring function etc) but still can't get it to work. Code and SQL are shown below. Does someone know where I've gone wrong? 'DateAssayRequested' is the date in question. <vb> 'set up and initialise connection conn = New SqlConnection(etc) comm = New SqlCommand comm.Connection = conn comm.CommandText = "SPSearch" comm.CommandType = CommandType.StoredProcedure 'create input parameters, set types and values param = comm.CreateParameter param.ParameterName = "@assayid" param.Direction = ParameterDirection.Input param.Value = txtLabNo.Text

Date validation problem modelstate.isvalid is false

In my view i am formatting the date as follows<%= Html.TextBox("MemoDate", string.Format("{0:dd/MM/yyyy hh:mm}", DateTime.Now),new{ @readonly = true })%> In controller ModelState.IsValid become false as my current culture culture {en-US} doesn't match with the format of date.

Problem with date values in data-driven subscription reports

Hello together, I have a question in regards of data-driven subscription report. I already have an ad-hoc report in place which can be customized by date etc. I now want to run these reports with a subscription. My challenge is now that I don't know how I can pre-define the date. I basically want the start date of NOW() and the end date 7 days in the past. I was looking around but did not get any clue where and how I have to configure it the way it works. I found this thread but honestly do not understand it well... :( http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/fb48fd15-09dd-4f5f-a09f-d92bf304c1a2 Can someone help me out please? M.

Problem displaying Date from Sql table on Calendar Control

Hi, I am displaying Event dates from SQL table on Calendar Control in ASP.NET. Also, I have GridView Control which shows event details when certain date is clicked on calendar control. But I have a problem as not all dates are displaying properly. Strangly enough only dates which have same month and day date are displayed. For example: It shows ok dates such as 08/08/2010, 09/09/2010, 10/10/2010 etc. If I click on the date which in SQL table exists as 11/25/2010 or 12/15/2010 etc (no matching month/day numbers) it shows error message saying: "System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string."  Follwoing is my code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Sql; using System.Runtime.Remoting.Messaging; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.Drawing; public partial class Test_Calendar : System.Web.UI.Page { SqlConnection mycn; SqlDataAdapter myda; DataSet ds = new DataSet(); DataSet dsSelDate; String strConn; private void Page_Load(object sender, System.EventArgs e) { strConn = "Data Source=mydatasource;Initial Catalog=DBname;Persist Security I

Date formate problem

Hi I have faced one problem with processing date field from xml file. i have read RSS site and get date field from this site and parse that date field using below code i got pubDate field from xml like : <pubDate >06 Sept 2010 09:15:01 +0300</pubDate > datefield = DateTime.Parse(xmlfile.Element("pubDate").Value.Replace("\n\r", "").Replace("\r\n", "").Replace("\n", "").Replace(" Sept "," Sep ").Trim(), FinishCulture.DateTimeFormat, DateTimeStyles.AdjustToUniversal).AddHours(3).ToString("dd.MM.yyyy HH:mm:ss"),   I have face this problem because of month format "Sept". i have also implement this functionality with other RSS site they working fine with above code as they return date like : <pubDate >06 Sep 2010 09:15:01 +0300</pubDate > So, the problem is with month name Sept - Sep. can you please tell me how can i handle "Sept" month name format.   Thanks Nikunj Padaliya  

Date Time interval Problem

Hi I have a problem in which i have to check the time interval to the another which is already exist in Database table.For Exp.10:00 am  To 11:00 am i add an Event now if user insert the again this time interval  it's throw the error message.if user want's to edit this event For exp.10:15 am to 11:00 amhow do this.Thanks

StrToMember problem with todays date.

Hi, I want a calculated member who will give me the bookvalues for todays month. When i run these two scripts (variables and hardcoded examples) in SQL server management studio the result are shown for both scripts no problem there: SELECT {[Measures].[Asset Bookvalue balance]} ON 0,  [MSN].[Asset].[Asset] on 1 from CMSX_DWH_OLAP  where {StrToMember("[Book Value Start Date].[Year - Quarter - Month].[Month].&["  + Format(now(), "yyyy") + "]&[" +  Format(now(), "MM") + "]")}       SELECT {[Measures].[Asset Bookvalue balance]} ON 0, [MSN].[Asset].[Asset] on 1 from CMSX_DWH_OLAP  where [Book Value Start Date].[Year - Quarter - Month].[Month].&[2010]&[09]   next step is to change the two scripts in order to be used as a Calculated Member: CREATE MEMBER CURRENTCUBE.[Measures].[Todate Asset Bookvalue balance]  AS ([Measures].[Asset Bookvalue balance],{StrToMember("[Book Value Start Date].[Year - Quarter - Month].[Month].&["  + Format(now(), "yyyy") + "]&[" +  Format(now(), "MM") + "]")}),  FORMAT_STRING = "#,#.00;(#,#.00)",  VISIBLE = 1  ;       CREATE MEMBER CURRENTCUBE.[Measures].[Todate Asset Bookvalue balance2]  AS ([Measur

Date Range Problem

How would I go about returning the closest ReleaseDate to DateIn? The record I would like to return is (2010-07-18 00:00:00.000 2010-07-17 00:00:00.000) CREATE TABLE #test ( ID INT ,DateIn DATETIME ,ReleaseDate DATETIME ) INSERT INTO #test VALUES(1, '07/18/2010', '01/10/2010') INSERT INTO #test VALUES(2, '07/18/2010', '07/17/2010') SELECT * FROM #test WHERE CONVERT(CHAR(10), '07/17/2010', 101) <= CONVERT(CHAR(10), '07/18/2010', 101) AND CONVERT(CHAR(10), '07/18/2010', 101) <= CONVERT(CHAR(10), '01/10/2010', 101) DROP TABLE #test  

problem in date format in sql 2005

I am new to sql2005  My problem is,  I send a date parameter (@fdt  and @Tdt)   like "DD/MM/YYYY" format through Sql reporting services My query is select  * from deposits where Depdate >= @fdt and Depdate <=  @tdt in the aove query there is no record has been fetched   But i give like this,  Inthis case i get a resultselect  * from deposits where Depdate >= '2010/04/01' and Depdate <= '2010/08/31' pls tell me how can i convert the date to "yyyy/mm/dd"    in where condition   Thanks Gk  

Problem with date type

hi i receive this date: `9/20/2010 3:32:32 PM` i need to convert to datetime. i try:     DateTime DateFrom = DateTime.ParseExact("9/20/2010 3:32:32 PM", "dd/M/yyyy", CultureInfo.InvariantCulture);                     but i get error: `String was not recognized as a valid DateTime.` in my computer the region is: `Hebrew (Israel)  dd/MM/yyyy for short date and hh:mm for short time` how to fix it ? thank's in advance

Problem with date validation.


I have the following code:

protected bool ValidGebdat()
    Regex LongDate = new Regex("^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-                   9]|3[01])[- /.][0-9]{4}$");

    string gebDat = GebdatTB.Text;

    string s = gebDat.Trim();

            if (LongDate.Match(s).Success)
                   return true;
                  return false;

Why do I get a return false when I insert "27-02-1970"?

XPath Date Formatting Problem


Hey all, just plain and simple I think....lol

Why will this not work?

<asp:Label ID='playDate' runat='server' Text='<%# XPath("LastPlayed", "{0:MMM d yyyy}") %>'></asp:Label>

It completely ignors my date formating and returns this result.


Oh yea, this is in a datalist using an XML datasource.

Performance problem with date range JOINs



when I am joining two tables where one table has two columns which specify a date range and the other table has one column with a single date which must be in that range for a join, then the performance is not so hot. The T-SQL example only shows the basic query scheme, in reality there are appropriate indexes (but not on the date columns since I found them not helpful) and the DateRange column has about 100 mio rows and the Incident table about 200,000 rows. The query currently takes hours, I must speed it up by at least factor 10.

TIA for any ideas. Regards

	[DateRangeID] [int] NOT NULL PRIMARY KEY,
	[RangeTypeID] [smallint] NOT NULL,
	[StartDate] [date] NOT NULL,
	[EndDate] [date] NOT NULL)

	[IncidentID] [int] NOT NU

Date formatting problem with BIDS


I've just moved to a new PC, and had BIDS installed on it.  All machine dates are set to the international standard (dd/MM/yyyy).

I just opened an existing report to modify it that includes a date range in the parameters.  When I tried to do a test preview of the report in BIDS, I got an invalid data error on the first date parameter.  After a bit of fiddling around, I worked out that it would only let me input the dates in US format, yet after input the dates are converted to international format.  When deployed to the report server, the report requires the dates to be input in international format.

I've spent half an hour checking my machine and BIDS to try and find the cause of this problem, and I'm stumped.

Any suggestions?

insert date problem when culture is arabic



I want to insert date value in database

when my page loads i am setting the culture into ar-sa

and when insert date i am getting the problem

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Public Sub Add_Date(ByVal title As String, ByVal Schedule_date As Date)
            command.CommandText = "sp_Schedule_DML"
            command.CommandType = CommandType.StoredProcedure
            If Schedule_date = Nothing Then
                command.Parameters.AddWithValue("@optSelect", 0)
                command.Parameters.AddWithValue("@title", title)
                command.Parameters.AddWithValue("@sdate", System.DBNull.Value)
                command.Parameters.AddWithValue("@optSelect", 0)
                command.Parameters.AddWithValue("@title", title)
                command.Parameters.AddWithValue("@sdate", Schedule_date)
            End If
            If connection.State = Data.ConnectionState.Closed Then
            End If
            If connection.State = Data.ConnectionState.Open Then
            End If
        Catch ex As Exception
            Throw New Exce

date time problem


hi i hv a table in ms-access that have a column in datetime format.when i add data to this field it get stored in the format dd/mm/yy with time as 12.00.00 am.i m binding this data in grid view.hw can i remove the time from the date as i dont wanna show time in the that column of grid view. i m binding the data in gridview by the template field binding methods  

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend