Purpose
Use this function to snap/round the date as per the given date units. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
DateSnap(input_date, date_unit, currentOrNext)
input_date (Date): A date input parameter
date_unit (String): Date units from below values.
- day
- month
- year
- week
- century
- decade
currentOrNext (Logical): Snap to current period or next.
Return Value
Date
Example
print DateSnap(19960302 ,"year", TRUE)
//returns 19960101
print DateSnap(19960302 ,"year", FALSE)
//returns 19970101
print DateSnap(19960302 ,"month", TRUE)
//returns 19960301
print DateSnap(19960302 ,"month", FALSE)
//returns 19960401
//This will snap to first day of week based on your system settings.
print DateSnap(20210525, "week", TRUE)
//returns 20210524
//This will snap to first day of week based on your system settings.
print DateSnap(20210525, "week", FALSE)
//returns 20210531
print DateSnap(20210525, "decade", TRUE)
//returns 20200101
print DateSnap(20210525, "decade", FALSE)
//returns 20300101
print DateSnap(20210525, "century", TRUE)
//returns 20000101
print DateSnap(20210525, "century", FALSE)
//returns 21000101