locked
Filter for yesterday and tomorrow from a table of dates RRS feed

  • Question

  • Hello everybody,

    I am new to Lightswitch and am making a small application for my company. I am stuck in a small problem and could not find it any answer.

    I have a table of Dates linked to another table of details od hours employes can insert hours.

    Have to filter a screen for all seven days in 7 tabs on one screen.

    just want to know how you can filter a screen for yesterday or tomorrow. In globalñ filter we can find start of week and end etc.

    Please help me ! 

    Thursday, May 14, 2015 4:42 PM

Answers

  • Hello

    I am not 100% sure that I understand what you are looking for but the below code will give you the current week for todays date.

    Dim todaysDate As Date = DateTime.Today
    Dim dayDiff As Integer = todaysDate.DayOfWeek - DayOfWeek.Monday
    Dim startWeekDay As Date = todaysDate.AddDays(-dayDiff) 'Monday
    Dim endWeekDay as Date = startWeekDay.AddDays(6) 'Sunday

    You can then use the startWeekDay and endWeekDay dates as filters on your main query to only show that week.

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)


    • Edited by Otis Ranger Monday, May 18, 2015 1:51 PM
    • Marked as answer by ParamSingh Monday, May 18, 2015 2:28 PM
    Monday, May 18, 2015 1:50 PM

All replies

  • Hi guys,

    Am new to Lightswitch and am preparing an desktop app for my company.

    My  problem is to open the whole present week in one screen, where the employes can enter their hours, projects worked, which is linked to the Date/week table.

    Please, help me to filter the screen for other days apart from the global ( Start of the week, end of the week ).

    Would appreciate any help.

    • Merged by Angie Xu Monday, May 18, 2015 6:18 AM same issue
    Friday, May 15, 2015 6:48 AM
  • Hi ParamSingh,

    You can add query to that table, click the "Edit Additional Query Code".

    Add code snippet like this:

    partial void Yesterday_PreprocessQuery(DateTime? BirthDate, ref IQueryable<Contact> query)
            {
                DateTime yesterday = DateTime.Now.AddDays(-1);
                //some other code snippet according to your requirement. 
            }

    Hope it helps.

    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Angie Xu Monday, May 18, 2015 6:15 AM
    Monday, May 18, 2015 6:12 AM
  • Hi Angie,

    I am very grateful for your kind reply.

    Actually, I am using VB Code and found yesterday came across a Thread from  YANN DURAN , Which I Thought solved my problem.



    BUT realized That It will not solve the problem.

    My Aim is to have A screen with  Only present Week, Where the employees Can add their Working hours and Projects.

    Maybe if I go on this way :

    We have (Start of the Week ) In GLOBAL QUERY. How to add days 1,2,3 to get this whole week ? 

    I have a Table of Days and corresponding weeks Which are linked to the Hours Detail Table and Project Table.

    I Hope I have been able to explain Correctly. :) Thanks a lot.

    Kind Regards,

    Param Singh.
    Monday, May 18, 2015 10:29 AM
  • Hello

    I am not 100% sure that I understand what you are looking for but the below code will give you the current week for todays date.

    Dim todaysDate As Date = DateTime.Today
    Dim dayDiff As Integer = todaysDate.DayOfWeek - DayOfWeek.Monday
    Dim startWeekDay As Date = todaysDate.AddDays(-dayDiff) 'Monday
    Dim endWeekDay as Date = startWeekDay.AddDays(6) 'Sunday

    You can then use the startWeekDay and endWeekDay dates as filters on your main query to only show that week.

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)


    • Edited by Otis Ranger Monday, May 18, 2015 1:51 PM
    • Marked as answer by ParamSingh Monday, May 18, 2015 2:28 PM
    Monday, May 18, 2015 1:50 PM
  • Thanks a Lot Otis !! You Guys are Just  Great !!!!

    I will be definitely Working With Lightswitch more for my company and maybe asking some more questions and suggestion from you .

    Kind Regards,

    Param Singh

    Monday, May 18, 2015 2:31 PM
  • Hi Otis,

    Have put a Problem since many Days and not recieving any Help !!

    Could you be Kind Enough to Help me on my Problem :

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/674abc7b-857d-4d4d-9464-1c6b0606e2b6/query-across-tables?forum=lightswitch

    ---------------

    I dont think it should be that difficult for so Experienced guys like you :).

    If I am not able to bring my problem across correctly kindly let me know and I will try again.

    Thanks in Advance.

    Param Singh

    Tuesday, June 2, 2015 3:11 PM