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

Top 5 Contributors of the Month
Sandeep Singh
Post New Web Links

Issue with date addition

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net


I am using ASP.NET, C# 2.0.

I am having a date issue. The error is "Year, Month and Day parameters describe an un-representable Datetime"

I am adding the date with 14 and 7 depending on a condition.

Below is the code I have used:

DateTime d = DateTime.Now;
int addDays =0;

if (Convert.ToString(Session["School"]) == "US" )
addDays = 14;
addDays = 7;

DateTime n = new DateTime(d.Year, d.Month, d.Day + addDays);


 The issue happens, if the date is 17 for US Schools and 25 for other schools, if the month has 30 days. This issue will happen for 28 days in February, and 30,31 days for other months.

How to add this 14 and 7 depending on the months. I know i have to increment the month by 1 and increase the date to the next month( and increase year to next, if done in december). But not sure, how to do this.

How to add this?

Thank you

View Complete Post

More Related Resource Links

Deserialization issue with returned from web service

Hi, I have a VS 2008 C#  client using a proxy generated by the Service Reference tool from a schema for a (prob Java?) ASMX web service.  I got serialisation errors when I tried connecting to the service around<xs:date> date fields, and on inspecting the incoming XML discovered the date format was yyyy-mm-dd hh:mm:ss.sss.   So 2 questions really.. 1) Is the schema I've been supplied with incorrect? 2)Is there a way to work around this, apart from manually editing the schema to xs:datetime and regenerating the classes?   Thanks MJ

Weird Date vs Date/Time issue using a calculated column

I'm attempting to use the fab 40 attendance template. I don't need the time to show - Im able to hide that on the forms with jquery (endusersharepoint.com thank you!!) I WAS ATTEMPTING to create a calculated column called Start Date where the formula simply reads '=[Start Time]' When it's set to display 'Date Only' the date is off by a day. If I switch it to 'Date & Time' I get the correct date. Huh?

Issue with CAML Query regarding date comparision.

I have a below query in one the eventhandlers. All I do in the query is to get all records where Next_Date column is < CurrentDateTime ( I have shown current date below in full date format but it will be variable).

What I am observing is the comparision seems to be failing or not considering time format. For example the below query should not return any records when NEXT_DATE is 9/30/2010 23:59:59 and CurrentDateTime is 9/30/2010 06:22:22. However the query does return records. It looks like the comparision is just happening with Date and not time. What could be the problem? Please suggest.

         <FieldRef Name='Next_x0020_Date' />
         <Value Type='DateTime'>2010-09-30T13:13:13Z</Value>
      <FieldRef Name='Next_x0020_Date' Ascending='False' />

Display Long Date Issue


I want to display my date as 15 October 2010. I am trying to use this:

=FormatDateTime(Today(), DateFormat.LongDate)

But am getting Friday, October 15, 2010. How can I format it properly?

Date Time issue in Sharepoint Designer workflow



I am trying to format the date in a Sharepoint workflow (using Sharepoint Designer 2007) so that it does not include the time.  Does anyone know how this can be done?


Any help greatly appriciated...



Srikanth Reddy




Issue with Pause Until Date


I'm trying to get a Pause Until Date action to work.  The problem is that when it reaches the date it never continues the workflow.  I've looked at a number of previous posts about issues with this action.  Most of them are from 2008 to 2009.  They speak about service packs, hot fixes, issues with .net framework, changes needed to be made by STADMIN.  But none of them that I can see talks about a clear resolution to the issue. Let me lay out the scenario and see if I'm doing something wrong.

I have an column called end date.  Because I want to have the workflow fire the day after end date, I created a calculated column called Run Date which adds 1 day to the end date.  I've checked and the Run Date is being calculated correctly. In the first step of my workflow I added a Pause Until Date action pointing to the column Run Date as the date to resume.  But it never resumes the workflow.

Here's the environment I'm working with:

Date conversion issue



I am using 2 SQL instances, one is remote on the server and one local on my machine.  Both instances have British date format settings, but one performs different to another.  I am calling a function in SQL Server from Access VBA.

For example, when I pass a date to a local instance in this format #31/03/2011# it doesn't work, although the date settings is British.

But when I pass to remote instance works fine on both formats, #31/03/2011# and #03/31/2011#  also the date settings is British.

I dont' understand why this happening. 

Can I also ask how to pass a date from MS Access VBA to SQL Server 2008 R2 in this format: yyyymmdd ?  As I thought the format is universal within SQL Server and should interpret dates regardless on settings.


Thank you

Date issue in jqgrid


Hi team,


In my project i have to display date columan in jqgrid i'll sending date formate like 5/21/2011 12:00:00 AM to jqgrid

but the grid prints like /Date(1305916200000)/ and my grid col is


{ name: 'Date', index: 'Date', width:100, center: 'right', sorttype: "datetime", datefmt: "m/dd/yyyy h:i AMPM", search: true, sortable: true },

please help me in this issue................

Date issue where the date stored in the db is one day delayed from the actual date set


hi -

i would like to ask if anyone encountered this issue,

i set the date to be 5/17/2011 in an entry to my sharepoint list

but when i checked the database, the date stored is one day delayed its, 5/16/2011

please help me.


Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

How To Set a Date Format In GridView Using ASP.NET 2.0

A very common desire is to set a column of a gridview to display just the month, day and year of a DateTime type. The problem is the by default, the HtmlEncode property of the boundfield attribute (
The problem is that if this field is enabled, you can not pass format information to the boundfield control. That is, if you try the following code, you will not get the desired result.

jQuery Date picker Implementation in ASP.NET

I've posted a wrapper ASP.NET around the jQuery.UI Datepickercontrol. This small client side calendar control is compact, looks nice and is very easy to use and I've added it some time back to my control library.

This is primarily an update for the jQuery.ui version, and so I spend a few hours or so cleaning it up which wasn't as easy as it could have been since the API has changed quite drastically from Marc's original implementation. The biggest changes have to do with the theming integration and the resulting explosion of related resources.

If you want to use this component you can check it out a sample and the code here:

How to format datetime & date with century?

Execute the following Microsoft SQL Server T-SQL datetime, date and time formatting scripts in Management Studio Query Editor to demonstrate the usage of the multitude of temporal data formats available and the application of date / datetime functions.


Date and Time Functions in SQLSERVER

Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

1 DATEPART Function
2 DATENAME Function
3 DAY, MONTH, and YEAR Functions
5 DATEADD Functions
6 DATEDIFF Function
7 More SQL Server Functions

Data Types - Date and Time in SqlServer

Date and time values can be stored with either the DATETIME or SMALLDATETIME data type. The difference between the two is that SMALLDATETIME supports a smaller range of dates and does not give the same level of precision when accounting for time. The DATETIME data type can hold values from January 1st of 1753 to December 31st of 9999. The time is stored to the 1 three hundredths of a second and each value takes up 8 bytes of storage. The SMALLDATETIME data type can hold values between January 1st 1900 and June 6th of 2079. The time is tracked to the minute and each value takes up 4 bytes of storage. The majority of business applications can live happily with SMALLDATETIME, however, if you are in an environment where each second matters or you need to make estimates to the distant future (or past) then you have to resort to DATETIME. If you fail to specify the time when inserting a value into a DATETIME or SMALLDATETIME column, a default of midnight is used. If you fail to specify the date portion the default of January 1, 1900 is used.

Built-in Functions - Date and Time Functions

Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

Essential SQL Server Date, Time and DateTime Functions

The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all.
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