You must Sign In to post a response.
  • Category: LINQ

    Compare a date which is stored as char(8) using LinQ


    In db, a date column is designed as Char(8).
    I want to compare if this date falls between 2 given dates.
    Where(tmp => tmp.DateField1.CompareTo(st_dt) >= 0 && tmp.create_dt.CompareTo(ed_dt1) <= 0)

    I tried this. But not getting expected results.
    Can anyone please correct me?

  • #764204
    Hai Shari,
    To compare the date, first your char(8) value should e converted to the date format and once it is converted, you can compare it.
    Select Cast(@s) as Date will give you the date format.
    Now you can use your old code which should work.
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #764206
    Hi Pawan,

    Thanks for the reply.
    This is the LinQ which am using to fetch a set of columns

    (from r in table1
    orderby r.DateField1 descending
    select r).Where(tmp => tmp.DateField1.CompareTo(st_dt) >= 0 && tmp.DateField1.CompareTo(ed_dt1) <= 0)

    Here how to cast the DateField1 to Date?


  • #764232
    With help of SQL you can use CAST method to cast input value to date and then compare see below snippet
    SELECT * FROM dbo.tbl_MyTable
    CAST(CONVERT(CHAR(10), DateTimeValueColumn, 102) AS DATE) = CAST(CONVERT(CHAR(10),GETDATE(),102) AS DATE)
    But in LINQ case you can use DateTime.Compare method
    DateTime.Compare(x.price_date.Value.Date, dt.Date) == 0).ToList();

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764234
    The Top Qualities And Features You Should Look For In A Good Hotel
    Going on an out-of-town or country vacation can rarely be a cheap endeavor. Air flight tickets or gas expenses can already eat up a chunk of the money you allotted for this trip. A lot of money can also go into various food or dining expenses as well. Of course, you will also have to spend a lot of money into the hotel room or accommodation where you and your family or trip buddies will stay during your vacation.

    There is no escaping the fact that your chosen accommodation will be one of the biggest expenses that you will have to prepare for when you go on a vacation. As such, it is important to make sure that every penny you spend on your selected accommodation is worth it. And you can do this by making sure that you choose a hotel that has the right qualities and features.

    The best hotel does not only boast of a grand lobby, beautifully landscaped garden, Olympic-sized swimming pools, and spacious rooms with a complete functioning entertainment system. There are other key qualities and features that you should look for a good hotel worth checking into. These include the following:

    Warm and genuine staff reception and treatment - The best hotels have employees that exude sincere kindness, cheerfulness, and warmth. In short, everyone that works in the hotel, from the front desk to the concierge and housekeeping, should make all their guests feel comfortable and important throughout their stay. And as a guest, you should feel the genuine warmth and kindness of the staff and not because they are paid to be hospitable to you.

    Properly appointed rooms or suites that meet your specific requirements - Today, the best hotels make sure that you are assigned to exactly the kind of room you requested for. They make sure you will stay in the room class or category and in the location (floor, proximity to elevators, etc.) you requested for. A good hotel should offer more than just a bed, bathroom, and TV set as well - it should provide distinctive accents and amenities that help you experience the local flavor. As such, hospitality consultants say that best hotels today should have rooms and suites that showcase high-quality bath and beauty products, and a basket of local treats like snacks and other goodies. They should also have ample drawer and closet space, a safe, hangers, free bottled water, robes and slippers.

    Everything is clean and orderly - The best hotels are always clean. The rooms, dining halls, washrooms, and every facility should always be clean and in order. The housekeeping staff should always spend sufficient time to clean your room thoroughly as well.

    Simple and easy booking - Lastly, whether you book a hotel online, on the phone, or through a travel agent, everything should be a simple process. It should be easy for you to contact a knowledgeable, helpful person if you have questions, changes to your initial booking, or some specific requests.

    Delete Attachment

Sign In to post your comments