Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: dateadd Post Reply Post New Topic
Author Message
twinkle
Newbie
Newbie
Avatar

Joined: 16 Jun 2008
Location: United Kingdom
Online Status: Offline
Posts: 32
Quote twinkle Replybullet Topic: dateadd
     Posted: 18 Dec 2008 at 9:29am
how does this formula work ????
 
DateAdd ('m' , 1 , {Orders.Order Date} - day({Orders.Order Date}) + 1) - 1
 
help


Edited by twinkle - 18 Dec 2008 at 9:29am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Dec 2008 at 8:31am
This is returning the last day of the month from the field {Orders.Order Date}.
For example 9-13-08 becomes 9-30-08.
The first part
DateAdd ('m' , 1 , {Orders.Order Date}
adds one month to the field (e.g. 9-13-08 becomes 10-13-08).
The second part
- day({Orders.Order Date}) + 1)
subtracts the total number of days from the month and then adds one day making it the first day of the new month (e.g. 10-13-08 becomes 10-1-08).
The last part
- 1
subtracts one day from the first day of this new date making it the last day of the previous month (e.g. 10-1-08 beomes 9-30-08).
The DateAdd function deals with off number months to handle things so as to not create invalid dates. For example adding one month to 1-31-08 will return a value of 2-29-08 instead of 2-31-08 which is invalid. It also handles leap years.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum