Date and Time Functions
Crystal Reports gives you a plethora of date and time related functions to utilize. You can also combine different functions together to create very powerful date calculations. There are a lot of new concepts to learn.
Table 6-12. Date and Time Functions
Function Name | Description |
---|---|
CurrentDate, CurrentTime, CurrentDateTime, PrintDate, PrintTime |
Returns the current date and/or time based on the Windows. |
DataDate, DataTime | The date and time that the report data was last refreshed. |
DateSerial(year, month, day),DateTime(hour, minute, second) | Returns a date or time for the specified paramaters |
DateAdd(interval, number, date) | Increases the date by a certain interval. |
DateDiff(interval, startdate, enddate, firstdayofweek) | Find the difference between two dates. |
DatePart(interval, date, firstdayofweek, firstweekofyear) | Return a number representing the current interval of a date. |
MonthName(date, abbreviate) | Return the full month name. When the second argument is True, it returns the 3-letter abbreviation. |
Timer | The number of seconds that have elapsed since midnight. |
WeekDay(date, firstdayofweek) | Return a number representing the day of the week. |
WeekdayName(weekday, abbreviate, firstdayofweek) | Return the full week name. Return the 3-letter abbreviation if the second argument is True. |
Table 6-13. Interval Strings for DateAdd(), DateDiff() and DatePart()
String | Description |
---|---|
yyyy | Year |
Q | Quarter |
M | Month (1 through 12) |
ww | Week of the year (1 through 53) |
W | Day of the week (1 through 7) |
Y | Day of year (1 through 366) |
D | Day part of the date (1 through 31) |
H | Hour |
N | Minute |
S | Second |
Printing the Current Date and Time
There are five functions which return a report’s date and time. The functions CurrentDate, CurrentTime, CurrentDateTime, PrintDate, and PrintTime all return the date or time that the report was printed. Although the functions Currentxxx and Printxxx have different names, they are synonymous with each other.
If you wish to back date a report, you can override the print date and time so that it doesn’t use the Windows clock. Go to the menu options Report > Set Print Date and Time. In this dialog box there is the option to use the Windows system date/time (the default selection) or you can set a specific date and time.
The functions DataDate and DataTime return the date and time that the report data was last refreshed. If a report has the Save Data With Report option turned on, this will tell you how current the data is.