.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

Find the nearest date before Saturday, Sunday and holidays with Linq

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

 var tecaji = (from xml in doc.Descendants(slazhnmaespace + "tecajnica")
                      where xml.Attribute("datum").Value == "2010-10-158"
                      select xml).Elements().Where(a => a.Attribute("oznaka").Value.Equals("TRY")).Select(n => n.Value).SingleOrDefault();

I have dates that are not in the XML file, but value still has to show.

In the table there is no value for the date of 23.10.2010, 24.20.2010. How do you show value for the date 10/22/2010?

Finding the appropriate date, which is najbluzjemu to that in the table.

In this XML table is not displayed dates (Saturday - Sunday).

Therefore, to find the nearest date before Saturday and Sunday.

If it is Saturday, the date "02.10.2010" shall be the date of "01/10/2010.

How do I get to that solution?


View Complete Post

More Related Resource Links

How to get the Nearest date with Linq


            var querysnajblizjidatum = (from xml in doc.Descendants(slazhnmaespace + "tecajnica")
                          where xml.Attribute("datum").Value == datumstroska.ToString("yyyy'-'MM'-'dd")
                                      //  where xml.Attribute("Datum").Value.Equals("10-21-2010") //< najblizjidatum 
                                        where (xml >= xml.Attribute("Datum").Value >= "10.5.2010")  
                          select xml).Elements().Where(a => a.Attribute("oznaka").Value.Equals(ddlValutaStroska.SelectedValue.Substring(0, 3))).Select(n => n.Value).SingleOrDefault();

How to get the Nearest date? My code does work.


If the date of 16.10.2010, I want print, 15.10.2010

If the date of 21.10.2010, I want print, 18.10.2010

If the date of 19.11.2010, I want print, 8.11.2010



Nearest date with Linq



If I choose the date 10.02.2010 and there is none, I want to find the earliest date.


Find a date that does not exist, it is 03.10.2010.
Given that the date in the table does not exist, I want to find 1.10.2010.

If I want to find 20.10.2010 and it does not find, print 15.10.2010.


How do I find nearest date with LINQ, if I can not find?

Get Dates from Sunday thru Saturday


I'm using the date picker and I need to know how (or if it's even possible), to select a date, and based on the date, have the actual query use the week the date was in and return all the records from that week (Sunday through Saturday)

Like - if I pick 8/24/2010 - it returns a date range of 8/22 through 8/28
I'd also like to display the date range in the report, somehow

Any ideas on how I do this?

Date help: I need the Sunday date that corresponds to any date

Hello I need to know the syntax for finding the Sunday Date that relates to any given date. Example, Monday August 23 2010 thru Sunday August 29th 2010 would all have the value of August 29 2010 Thank you -

Converting Date to String and Formating it Linq to SQL

Hello I have problem in converting date to string I am using cstr(p.tripstart) , which is returning Date as 12 Aug 2010 12:AM   I need to make formating   This is my code : Dim db As New TripsLinqDataContext Dim listtrips = (From p In db.Trips _ Group Join c In db.Countries On p.TripCountryID Equals c.TripCountryID Into countrylist = Group _ Select New With {.Tripdetails = p.TripDescription + " - " + p.TripCityList + " - " + CStr(p.tripstart) + " - " + CStr(p.TripDays), _ .Tripid = p.TripID}).ToList tripboxlist.DataSource = listtrips tripboxlist.DataTextField = "Tripdetails" tripboxlist.DataValueField = "Tripid" tripboxlist.DataBind()     Regards  

how to find local time and date usin gmt time and ofset value

Hi All, i have to calculate local time and date in our data base i have gmt time range from 00:00 to 23:59 and offset is in same range but with + an - sign when + then we have to substract and when - then we have add and adjest the date with the given time for eg  gmt id 23:30 and ofset is +2:30 and date is '28-08-2010' then my local time is 23:30 -2:30  =21:00 and date will not change i want a cricteria like when offset get added then value should not be like 22:60 insted of this it is 23:00 and if it is exiding 24 then date should be increase and if time is - after gmt+ofset then date should be redused   Please give me a idea so i can solve it.  

Compare Date in LINQ

Dear all, How to do in LINQ?? And below is correct or not if put string.format in LINQ??   Datetime updatedDate=DateTime.Now; string upddate=string.format("yyyy-MM-dd", updatedDate); var result=( from p in W_Order                   where string.format("yyyy-MM-dd", p.orderdate) == upddate                    select new order {                       .........                        }).toList();            

Please help me to find out distinct value from linq to sql query given.

profileuserDataContext db = new profileuserDataContext(); var Q = (from p in db.edufinals join RM in db.edufinals on p.UserName equals RM.UserName where p.name.StartsWith(srcval) select new { p.name, RM.ProfielID, RM.ProfielPic, RM.city }).OrderBy(x => x.name).Distinct().Take(10);//, p.Key.ProfielID, p.Key.ProfielPic, p.Key.city, p.Key.country foreach (var pg in Q.Distinct()) { Response.Write(pg.name); ..................................... .................................... } how to refine this query to get distinct "name" column? Please help me to find out exact value.

how to find the nearest element in a sorted set?

.NET provides a lot of functionality for sorted collections, in particular the generic classes: SortedSet<T> SortedList<Tk key, Tv Value>,  SortedDictionary<Tk key, Tv Value>,  A common task when dealing with sorted sets, is to find the closest key in the sorted collection to a given key (above or below) E.g. SortedSet<int> ss = new SortedSet<int>() {1,3,5,7} int i = 4 is there a function that tells me that i=4 is between the second and the third element of the set ss? something like ss.FindHighestBelow(i) or ss.FindLowestAbove(i) Similarly with SortedList and SortedDictionary (find the closest key to a given one, above or below...) Clearly one could implement explicitly, but given the generic nature of the task and the large amount of functionality already in .NET, I suspect it is already there, somehow... thank you in advance, alberto

VWD 2010 and Linq to Sql: can't find a query model for...



I have added a linq to sql layer in my MVC 2 application.

This is the code I am using:

using (ProductPortalDataContext ctx = new ProductPortalDataContext())
                var Title = from aps in ProductPortal.Models.AppSettingsView
                            where aps.LanguageID = Lang
                            select aps.WebSiteTitle;

It says to be unable to find a quey model for AppSettings view and then says "where not found".

Tried googling, nothing came up. Tried searching here(first two pages) and nothing that seemed relevant popped up.

But the best of all, created a new ASP.NET applicatio, imported the model using Linq to SQL and it compiled!

No idea what I am doing wrong... hints?

(some time later...)

Ok, I tried adding a button and a label to the asp.net application j

find Hours Between Two Date

I Have two columns in my database datatype is datetime, now i want to find the difference in hours between two dates.

Remove Saturday and Sunday from Calendar Web Part View MOSS 2007



Is there a way to remove Saturday and Sunday from the default calander web part view.  I need to get my calendar to fit in a 800x600 window, so users do not have to scroll.  I would just like for the calendar to show Monday through Friday.

Find date of minumum score


I am trying to find the date when a person had their lowest score. I have tried something like this and it fails everytime that there are muliple answers:



select (updated_date) from person_detail where



How to retreive next sunday date from present date.


HI ,

I have created report in which i have to show date in one column and in other immediate sunday date from that date.tell me how to do the same in SSAS reports.


e.g if today is 14 oct,10 ,i want to show as below



col1     col2

14oct,10  17 oct,10 

where 17 oct,10 is Sunday.


for other e.g


supoose col1 date is 7 oct then data should be like this



col1     col2 
6OCt,10 10 oct,10

where 10 oct,10 is sunday.


Kindly Suggest




MDX - Find last leaf member of Date dimension under selected member of Date dimension, independently


Hi all

I need to reproduce the behaviour of the averageofchildren function with the exception that the function should always build the average of all members (even when the value of a member equals null). As you know average of children function always build the average at the lowest level of the time dimension.

My date dimension looks like the following:

[Date].[Fiscal] user defined hierarchy:




if context of [Date].[Fiscal].CurrentMember corresponds to a Week, I can retrieve all weeks before the current week using

In Period: MTD([Date].[Fiscal].CurrentMember)  -- PeriodsToDate also works fine

In Year: YTD([Date].[Fiscal].CurrentMember)

if context of [Date].[Fiscal].CurrentMember corresponds to a Period

How can I get all weeks (NOT Periods!) contained in all Periods before and within current period since start of year?

What would be a generic expression that retrieves all weeks before and in independently of level of selected Date dimension member




How to write the Web service in asp.net for Windows mobile application which find the nearest Restu


hi , i am developing the window mobile application in Asp.net, which will find the nearest Restaurant map on window mobile, but i am new to asp.net ,

  how to write the web service  in which i send my location address and  through window mobile and the web serivce find the neareset Restaurant map on window mobile ,

can this is possible ?

please help me

i dont know how to write the web service for this problem ,


please help me


many thanks in advacne


How to retrive a date time value from TimeStamp column using Linq?


I have a Timestamp column in my Table. I want to read the date time value and display in UI.

In Linq the Timestamp column is represented as System.Data.Linq.Binary.

I dont know how to retirve date time value in "MM-dd-YYYY" format from this Linq.Binary


- Why I am using Timestamp?.

I want to perform some operations based on the last modified date time of the particular row. Since I am using TimeStamp column in my Table as version column, It will contain the last modified date details, So i want to read the date time value from this time stamp column to do some other operations.



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