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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

comparing date values

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :ASP.Net
ScenarioI have records that have an initial value of 'blue' and stay 'blue' until after 2 days then they turn to 'green', Turn 'orange' after 15 days and then after 20 days turn 'red'.The results will be pulled into a gridview.What I'm having difficulty is; what's the best way of calculating the days, in sql server or in c#?Trying to get construct date examples is proving to be a bit of a pain: DateTime TodaysDate = DateTime.Now; DateTime SelectedDate = Calendar1.SelectedDate; TimeSpan result = SelectedDate - TodaysDate; int days = result.Days; lblCalculateDays.Text = days.ToString(); TextBox1.Text = TodaysDate.ToString("d"); TextBox2.Text = SelectedDate.ToString("d"); protected void Calendar1_SelectionChanged(object sender, EventArgs e) { putDateInBox(); } protected void putDateInBox() { lblCalDate.Text = Calendar1.SelectedDate.ToShortDateString(); }has anyone done something similar and found a good way of doing this?

View Complete Post

More Related Resource Links

Comparing Enum values in a collection - BC42025: Access of shared member, constant member, enum mem


I am upgrading from asp1.1 to 2.0

I use collection classes to sort data (e.g in datagrids etc)


Enum newsFields
End Enum

Public Overloads Sub Sort(ByVal sortField As newsFields, ByVal isAscending As Boolean)
Select Case sortField
Case newsFields.title

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.

Comparing Null Values(from variable) in SSIS

Hi All I need to create a script that checks to see if a variable value is NULL, if it is then it executes the next SQL Task and if not then the package has finished. I have this in a SQL 2000 DTS package script: Function Main() If isnull(DTSGlobalVariables("NextLoadDate")) Then Main = DTSStepScriptResult_DontExecuteTask Else Main = DTSStepScriptResult_ExecuteTask End if End Function As you can see, all I want to do is check to see if a variable is null then don't execute the next task. But i cannot get it to work in a SQL 2005 SSIS package, so far I have created a script and come up with the following: Public Sub Main() If Dts.Variables("NextLoadDate").Value.ToString <> "" Then Dts.TaskResult = Dts.Results.Success Else Dts.TaskResult = Dts.Results.Failure End If End Sub Any Ideas? Thanks BigGopher

Comparing columns with NULL values--Merge says unmatched when data is matched.

I found the article below describing this same issue with the Oracle merge statement.  It also described a work-around:    http://searchoracle.techtarget.com/tip/Merging-datasets-with-NULL-values I have been unable to find a solution to this issue for SQL Server 2008.  I am trying to do basic ETL from Staging table to a Type II dimension table in a Data Warehouse.  I am using the Merge statement with the Unique key minus the modification date as my merge key list.  I have a handful of columns (in both Staging and the DW) containing nulls in my merge key list.  I have tried the ISNULL function and the ANSI_NULL db option (OFF) with no success.  When I put zeros in the null columns, it works as expected.  I am about to try separate INSERT and UPDATE statements, but I fear that the NULL comparison issue will bite me there with the JOIN statement.  Has anyone else experienced this?  NULL values are valid in our Data Warehouse.  How can I make T-SQL handle them? Thank you for your help, Jesse

How to filter comparing two date attributes?

I am trying to create a report which will display Customer, Customer Request Date, Scheduled Arrival Date and Invoiceable Sell. I want to select this information where the Customer Request Date <= Scheduled Arrival Date. I have been trying various filter combinations, but I cannot get the correct syntax.   Here is my MDX code: SELECT NON EMPTY { [Measures].[Order Lines Invoiceable Sell]} ON COLUMNS, NON EMPTY {[Customers].[Customer].ALLMEMBERS *[Customer Request Date].[Short Date Alpha].ALLMEMBERS * [Scheduled Arrival Date].[Short Date Alpha].ALLMEMBERS} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Orders Quotes Projects] CELL PROPERTIES VALUE, BACK_COLOR,FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS    

Calculated Measure Help - Comparing Months from two Date Dimensions

Hello:   I have a Measure Group that has two Date dimensions, a Reporting Date and a Fee Paid Date. The Reporting Date and the Fee date is based on the same Dimension, which has a standard YQMD hierarchy. It's very typical. The calculation is called "Fees Paid In Same Period", and it would display the Fees paid if the Reporting Month equals the Fees Paid Month.   How do i do this?   Thanks,

Comparing Binary values in sp_executesql



I am using a stored procedures to handle some maintainance stuff in my DB, I have a binary field called Container, that for all rows that have that specific container I need to remove the oldest n rows, I also have a time field so I can order by it, in addition my table is recursive and so if I delete one value I need to delete all it's children.

So in short what I did is create a CTE that selects all the lines that I want to delete, using SELECT TOP @n FROM mytable WHERE Container=@Container

Now I had to use sp_executesql due to using a variable to declare the TOP value, but now it won't let me compare the binary value stating that nvarchar and varbinary data types are incompatible through add operator (I tried to do Container='+@Container+')

How can I do this properly?


comparing a date in string format to date


I have a program that is using credit card info and the expiration date is selected by the user clicking a dropdownlist for the month and a dropdownlist for the year.  I want to show a label message if the user tries to proceed while the month and year are evaluated as being earlier that the current month/year.  Can someone help me determine how to evaluate this? 

import-spweb changes some values (create date, modified...)


all my Imported items (export-spweb - >import-spweb) have today's date now.
And the creater is now mydomain\administrator.

Can I fix this somewhere ?
Maybe in a SQL table ?


display / insert values by comparing 2 columns of a table



i have a table which has the following columns 

A_ID, A_Value,A_Date,B_ID,B_Value_B_Date


i have another table as follows

A_ID,B_ID,A_Value,B_Value, Date


this is to be done 

* if A_date and B date are equal, one record shoould be entered to the TABLE 02. the values should be A_ID,B_ID,A_Value_B_Value and A_Date (since the date is equal, no problem; even can insert B_Date instead of A_Date)

* if A_Date and B_Date are different, then the following should happen

insert one record to TABLE02 as A_ID,B_ID, A_Value, 0 , A_Date

insert another record to TABLE02 as A_ID,B_ID, 0 , B_Value, B_Date


(As you can see, when the date differs we enter the single record of Table 01 into 2 recoerds in table 02. the Value column and Date column are related in such a way that when A's date is entered, the value for B should be 0 and vise versa..)


i tried having a UDF but in halfway remembered that we cannot include INSERTS in UDFs..

can anyone please explain me how can i solve this problem ??


PS: For your reference , i've sketched a diagram. please click on this link to view it for further clarifications



thanks in advance

-novicedba :)

Restricting Date Parameter Values


I have a daily revenue report (with 1 date parameter) that runs daily via report subscription.  Is there a way to restrict the date parameter so it can only select from 2009/1/1 up to Yesterday.  Our daily ETL process will process yesterday's data around 6:00 am, if the user picks a wrong date then the report will be incomplete.  I use =DateAdd("d",-1,Today()) for my default date parameter.

Is there a way to come up an explanation or a message  that “processing has not completed” or “data not available” if the user try to pull a report with wrong date?


Thanks, Michael Mei

SPD Workflow Associated with a Document Library Deletes all Date Values


A client has encountered an issue where they created an SPD workflow, associated with a document library, set it to start manually,  that updates one of the metadata columns using the "Set Field in Current Item" activity.  Once that step completes all the date values in the metadata columns are missing.

Upon further inspection, we determined that this is only occurring for office documents.  It deleted the dates for word and excel documents and did not for text and pdf documents.

We are able to duplicate ths on 2 different servers that are both on service pack 2.

We have tried different version settings on the document library and making the date metadata columns required.  No luck.

To recreate this issue:

1.  Create a new document library and added additional metadata columns to it.  Make some of these columns dates. 

2.  Create a new SPD workflow associated with the newly created document library 

3.  Add a "Set Field in Current Item" activity to the workflow and set one of the non date columns to a different value.

4.  Upload a word document and make sure to fill out the date fields.

5.  Kick off the workflow manually.

6.  Once the workflow

Problem with date values on forms libraries



I have some InfoPath form with date input field published as a content type to forms library. When I choose a date for example 2010 - 10 - 12 in my form, sharepoint column shows 2010 - 10 - 11T22:00:00. There's always one day shift between date choosen from form and shown on a list.

Query Builder - Show values where date is greater than DateTime now


Visual Web Developer 2010 Express

ASP.Net and C#


Hi Guys,

My issue is that I am pulled three tables together using the Query Builder and I only want to show data where a specific date is greater than todays date. Here is what i have so far:

SELECT        salesitems.sona, salesitems.sonitem, ZOverdueOrders.ZOOType, ZOverdueOrders.ZOOReason, salesitems.sduedate, salesitems.soitemstate
FROM            salesorders INNER JOIN
                         salesitems ON salesorders.son = salesitems.sona LEFT OUTER JOIN
                         ZOverdueOrders ON salesitems.sona = ZOverdueOrders.ZOOSON AND salesitems.sonitem = ZOverdueOrders.ZOOSONI
WHERE        (salesitems.sduedate > CONVERT(DATETIME, '2010-09-01 00:00:00', 102))
ORDER BY salesitems.sona, salesitems.sonitem

Where it says '2010-09-01 00:00:00' I want that to be the todays date.


Is this possible? Can anyone help please?

Thanks in advance for any help!!!!




Date values...How to add a time into the value (ie mm/dd/yyyy 23:59:00)?



I have a SQL query:

ALTER PROCEDURE dbo.GetDownloadDetails_Date
 (@StartDate DateTime,
 @EndDate DateTime)
 SELECT     StatusDate, ProgramName, UserFullName, LoginName, CostCenterCode, EmailAddress, Phone, Manager, ComputerName, SCCMSiteCode, Status,
                       FailureReason, PONumber
 FROM         Installs
 WHERE     StatusDate BETWEEN @Startdate AND @EndDate
 ORDER BY StatusDate

If the user selects a date range, the last day isn't populated, or if they select a single date, that date isn't displayed.  I know the reason as it's because the Statusdate is a DateTime...I manually entered, for the @EndDate 04-10-2011 23:59:00 for the @EndDate and the report generated.

So my question is how can I automatically update the @EndDate to include the time 23:59:00?

Query for Values based on Max Date


I need to find distinct Courses a Student has taken but the ones with Max date. Suppose we have the following data:

ID               Student             Course                Date      

1               Stu-100             Crs1                23/03/2009

2               Stu-100             Crs1                20/06/2010

3               Stu-100             Crs1               14/01/2011

4  &n

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).
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