datetime.4gl
- {***********************************************************************
- datetime
- This module contains functions which allow datetime variables to be
- manipulated in various ways.
- This module contains the following functions:
- Date_Plus_Time
- Month_Integer_to_String
- Max_Day_of_Month
- End_of_Next_Month
- First_Day_of_Month
- Last_Day_of_Month
- Add_Month
- File_Date_Stamp
- File_Time_Stamp
- Most recent change: Cathy Kipp March 5, 1993
- ***********************************************************************}
- {***********************************************************************
- Date_Plus_Time
- This function adds a datetime variable year to day to a datetime
- variable hour to minute.
- Input: date_datetime datetime year to day
- time_datetime datetime hour to minute
- Output: total_datetime datetime year to minute
- ***********************************************************************}
- function Date_Plus_Time (date_datetime, time_datetime)
- define date_datetime datetime year to day,
- time_datetime datetime hour to minute,
- total_datetime datetime year to minute,
- date_char char (10),
- time_char char (5),
- datetime_char char (16)
- whenever error continue
- { Convert date and time inputs to character inputs }
- let date_char = date_datetime
- let time_char = time_datetime
- { Format new datetime field }
- let datetime_char = date_char clipped, " ", time_char clipped
- { Assign datetime value to datetime variable }
- let total_datetime = datetime_char clipped
- return total_datetime
- end function { Date_Plus_Time }
- {***********************************************************************
- Month_Integer_to_String
- Input: month_num small integer from 1 to 12
- Output: month_name char (10), name of month
- ***********************************************************************}
- function Month_Integer_to_String (month_num)
- define month_num smallint
- define month_name char (10)
- case (month_num)
- when 1 let month_name = "January"
- when 2 let month_name = "February"
- when 3 let month_name = "March"
- when 4 let month_name = "April"
- when 5 let month_name = "May"
- when 6 let month_name = "June"
- when 7 let month_name = "July"
- when 8 let month_name = "August"
- when 9 let month_name = "September"
- when 10 let month_name = "October"
- when 11 let month_name = "November"
- when 12 let month_name = "December"
- otherwise
- error "Invalid month number."
- let month_name = "Invalid"
- end case
- return month_name
- end function { Month_Integer_to_String }
- {***********************************************************************
- Max_Day_of_Month
- This function receives a month and year number as input, and
- calculates the what the largest day of this month was. (Yes, it
- does account for leap years.)
- Input: month_num small integer from 1 to 12
- year_num small integer
- Output: max_day smallint (28, 29, 30 or 31)
- ***********************************************************************}
- function Max_Day_of_Month (month_num, year_num)
- define month_num, year_num, max_day smallint
- case (month_num)
- when 1 { January }
- let max_day = 31
- when 2 { February }
- if year_num mod 4 = 0 then
- let max_day = 29
- else
- let max_day = 28
- end if
- when 3 { March }
- let max_day = 31
- when 4 { April }
- let max_day = 30
- when 5 { May }
- let max_day = 31
- when 6 { June }
- let max_day = 30
- when 7 { July }
- let max_day = 31
- when 8 { August }
- let max_day = 31
- when 9 { September }
- let max_day = 30
- when 10 { October }
- let max_day = 31
- when 11 { November }
- let max_day = 30
- when 12 { December }
- let max_day = 31
- end case
- return max_day
- end function { Max_Day_of_Month }
- {***********************************************************************
- End_of_Next_Month
- This function receives a date as input, and returns a date which is
- the last day of the next month.
- Input: input_date date
- Output: output_date date
- ***********************************************************************}
- function End_of_Next_Month (input_date)
- define input_date, output_date date
- define month_num, year_num, max_day smallint
- call Add_Month (month (input_date), year (input_date))
- returning month_num, year_num
- call Max_Day_of_Month (month_num, year_num) returning max_day
- let output_date = mdy (month_num, max_day, year_num)
- return output_date
- end function { End_of_Next_Month }
- {***********************************************************************
- First_Day_of_Month
- This function receives a date as input, and returns a date which is
- the first day of the current month.
- Input: input_date date
- Output: output_date date
- ***********************************************************************}
- function First_Day_of_Month (input_date)
- define input_date, output_date date
- let output_date = mdy (month(input_date), 1, year(input_date))
- return output_date
- end function { First_Day_of_Month }
- {***********************************************************************
- Last_Day_of_Month
- This function receives a date as input, and returns a date which is
- the last day of the input month.
- Input: input_date date
- Output: output_date date
- ***********************************************************************}
- function Last_Day_of_Month (input_date)
- define input_date, output_date date
- define max_day smallint
- call Max_Day_of_Month (month (input_date), year (input_date))
- returning max_day
- let output_date = mdy (month (input_date), max_day, year (input_date))
- return output_date
- end function { Last_Day_of_Month }
- {***********************************************************************
- Add_Month
- This function accepts a month and year number as input, adds one
- month and returns them.
- Input: month_num smallint >=1 and <=12
- year_num smallint
- Output: month_num smallint >=1 and <=12
- year_num smallint
- ***********************************************************************}
- function Add_Month (month_num, year_num)
- define month_num, year_num smallint
-
- if month_num < 12 then
- let month_num = month_num + 1
- else { month_num = 12 }
- let month_num = 1
- let year_num = year_num + 1
- end if
- return month_num, year_num
- end function { Add_Month }
- {***********************************************************************
- File_Date_Stamp
- This function returns a date stamp of the current date suitable for
- naming a file.
- Input: None
- Output: p_date_char char (8)
- ***********************************************************************}
- function File_Date_Stamp ()
- define p_date date
- define p_date_char char (8)
- let p_date = today
- let p_date_char = p_date using "yyyymmdd"
- return p_date_char
- end function { File_Date_Stamp }
- {***********************************************************************
- File_Time_Stamp
- This function returns a time stamp of the current time (yymmddhhmm)
- suitable for naming a file.
- Input: None
- Output: time_stamp char (10)
- ***********************************************************************}
- function File_Time_Stamp ()
- define p_date date
- define p_date_char char (6)
- define p_time datetime hour to minute
- define p_time_char char (5)
- define time_stamp char(10)
- let p_date = today
- let p_date_char = p_date using "yymmdd"
- let p_time = current hour to minute
- let p_time_char = p_time
- let time_stamp = p_date_char, p_time_char [1,2], p_time_char [4,5]
- return time_stamp
- end function { File_Time_Stamp }
複製代碼
|