Get the Number of the day eg 150

TESDeveloper
Member Posts: 42
Hi,
How in Business Central code can I get the current day in it's number equivalent. So for example 1st February is the 32nd out of 365.
Thank you.
How in Business Central code can I get the current day in it's number equivalent. So for example 1st February is the 32nd out of 365.
Thank you.
0
Best Answer
-
var CurrentDate: Date; EarlierDate: Date; begin CurrentDate := Today(); //12th of June, 2020 EarlierDate := DMY2Date(1, 1, 2020); //January 1st, 2020 Message(StrSubstNo('Date 1: %1 - Date 2: %2 - Subtracted: %3', CurrentDate, EarlierDate, CurrentDate - EarlierDate+1)); //Message = "Date 1: 12-06-20 - Date 2: 01-01-20 - Subtracted: 164"
You can just subtract a Date with January 1st of the relevant year from the date you're trying to find the number of.
If you compare with January 1st, you have to add 1 to the result, since it doesn't also count the day of January 1st. Or you can set the "EarlierDate" to 31st of December to the prior year.5
Answers
-
var CurrentDate: Date; EarlierDate: Date; begin CurrentDate := Today(); //12th of June, 2020 EarlierDate := DMY2Date(1, 1, 2020); //January 1st, 2020 Message(StrSubstNo('Date 1: %1 - Date 2: %2 - Subtracted: %3', CurrentDate, EarlierDate, CurrentDate - EarlierDate+1)); //Message = "Date 1: 12-06-20 - Date 2: 01-01-20 - Subtracted: 164"
You can just subtract a Date with January 1st of the relevant year from the date you're trying to find the number of.
If you compare with January 1st, you have to add 1 to the result, since it doesn't also count the day of January 1st. Or you can set the "EarlierDate" to 31st of December to the prior year.5 -
-
Never mind, I thought the "Period No" was the day in the year but it looks like it is the day of the week.
0 -
kk-1
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