How to compare dates with today's date?

Aravindh_Navision
Member Posts: 258
Hi Friends,
In a report I have declared 4 date variables dtA, dtB, dtC, dtD and assigning dates to these variables from 4 different tables.
Case 1:
For example:
dtA = 25/08/2014 (from Vendor Ledger Entry)
dtB = 01/09/2014 (from Purchase Header)
dtC = 29/08/2014 (from Change Log Entry)
dtD = 26/08/2014 (from Vendor - Last Modified Date field)
I need to compare each of the above dates with today's date and take the date which is nearer to today's date. Say in this case 01/09/2014 (dtB) is the one.
Case 2:
I need to add these dates in a temporary table for any date field and sort it in incremental order and I can take the last value. This is also an option. How can I add the above dates in a temporary table?
Can anyone explain me how to do these 2 cases? Also tell me which one is the easiest one.
Thanks in advance.
In a report I have declared 4 date variables dtA, dtB, dtC, dtD and assigning dates to these variables from 4 different tables.
Case 1:
For example:
dtA = 25/08/2014 (from Vendor Ledger Entry)
dtB = 01/09/2014 (from Purchase Header)
dtC = 29/08/2014 (from Change Log Entry)
dtD = 26/08/2014 (from Vendor - Last Modified Date field)
I need to compare each of the above dates with today's date and take the date which is nearer to today's date. Say in this case 01/09/2014 (dtB) is the one.
Case 2:
I need to add these dates in a temporary table for any date field and sort it in incremental order and I can take the last value. This is also an option. How can I add the above dates in a temporary table?
Can anyone explain me how to do these 2 cases? Also tell me which one is the easiest one.
Thanks in advance.
0
Comments
-
function GetClosestDate ( Date1 : Date, Date2 : Date ) : Date Begin if date1 = 0d then exit(date2) ; if date2 = 0d then exit(date1) ; if abs(today - date1) < abs(today - date2) then exit(date1) else exit(date2) ; end ;
then in your main code :Closestdate := dtA ; Closestdate := GetClosestdate(Closestdate,dtB) ; Closestdate := GetClosestdate(Closestdate,dtC) ; Closestdate := GetClosestdate(Closestdate,dtD) ;
Your approach using a temp. table won't work as you state it, because the highest date is not necessarily the one closest to today.0 -
Thank you Berger. It worked... :thumbsup:0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions