Formatting Date

Kremena Hagen

New Member
Hi,

Is there a date formatting function in Progress that converts a date with a format MM/DD/YY to YYYY/MM/DD.

Thank you,


Kremena
 

jongpau

Member
Hi,
Do you need to assign the date into a character variable, display it or something like that? If not, it does not matter what format you use, the format is just a display format and Progress stores the date in just the same way (as a number, not the actual date).

Anyway, try setting the DATE-FORMAT of the SESSION handle to "YMD" and then displaying or assigning the date with format "9999/99/99".
 
/***************************************************************************************
**
** P R O C E D U R E
** -----------------
**
** File: general/datetime.p
**
** Author: Chris Paulson
**
** Date: 22-May-02
**
** Description: Given a format convert a string into a date/time
**
** Mod history:
**
***************************************************************************************/

/************************************* Parameters *************************************/
define input param pString as char no-undo.
define input param pFormat as char no-undo.
define output param pDateTime as decimal no-undo.
define output param pError as char no-undo.
/************************************* Scope Defines **********************************/
/************************************* Includes ***************************************/
/************************************* Shared *****************************************/
/************************************* Vars *******************************************/
define var vold as char no-undo.
define var vDateLength as int no-undo.
define var vDate as char no-undo.
define var vDateFormat as char no-undo.
define var vTime as char no-undo.
define var vDateValue as date no-undo.
define var vTimeValue as integer no-undo.
/************************************* Widgets ****************************************/
/************************************* Frame ******************************************/
/************************************* Triggers ***************************************/
/************************************* Main *******************************************/
vold = session:date-format.


run GetDateFormat( pFormat, output vDateFormat ).
vDate = substring( pString, 1, length(vDateFormat)).
vDateFormat = replace( vDateFormat, "CC", "YY" ).
vDateFormat = replace( vDateFormat, "YY", "Y" ).
vDateFormat = replace( vDateFormat, "YY", "Y" ).
vDateFormat = replace( vDateFormat, "MM", "M" ).
vDateFormat = replace( vDateFormat, "DD", "D" ).

session:date-format = vDateFormat.


vDateValue = date( vDate ) no-error.
if error-status:error then do:
pError = error-status:get-message(1).
return.
end.

vTime = replace(pString, vDate, "").

run general/time2int.p( vTime, output vTimeValue ).
if return-value = "bad":u then do:
pError = "Invalid time".
return.
end.

pdateTime = vDateValue - 01/01/0001 + (vtimeValue / 100000).

session:date-format = vOld.

/************************************* Procedures *************************************/
/***************************************************************************************
**
** Procedure: getDateFormat
**
** Description:
**
***************************************************************************************/
procedure getDateFormat:
/************************************* Parameters *************************************/
define input param pString as char no-undo.
define output param pDate as char no-undo.
/************************************* Vars *******************************************/
/************************************* Widgets ****************************************/
/************************************* Frame ******************************************/
/************************************* Triggers****************************************/
/************************************* Main *******************************************/
pDate = replace( pString, ":", "" ).
pDate = replace( pDate, "HHMM", "" ).
pDate = replace( pDate, "SS", "" ).
end.
/************************************* End Proc ***************************************/
 
/*
** File: general/time2Int.p
**
** Author: Chris Paulson
**
** Date: 9-Mar-95
**
** Calculates a string time into the number of seconds
**
** Mods:- CJP 6-May-97
** Updated to cope with more time formats
*/

define input param string as char no-undo.
define output param val as int no-undo.
/*******************************************/
define var sec as int no-undo.
define var min as int no-undo.
define var hour as int no-undo.
define var is24Hour as log no-undo.

if (string = "") or (string = ?) then do:
val = ?.
return "good":u.
end.

if substring(string, 2,1) = ":":u then
string = " ":u + string.

/*
** Remove ":" if there is one
*/
string = replace(string, ":":u, "").

/*
** Check for PM so we can add 12 hours onto clock
*/
if (string matches "*pm*":u) then
is24Hour = yes.
else
is24Hour = no.
/*
** Remove any AMs or PMs
*/
string = replace(string, "am", "").
string = replace(string, "pm", "").

if length(string) > 4 then
sec = integer( substring(string, 5) ) no-error.
else
sec = 0 no-error.

if error-status:error then
return "bad":u.

min = integer( substring(string,3,2) ) * 60 no-error.

if error-status:error then
return "bad":u.

if is24Hour then
hour = (integer( substring(string,1,2) ) + 12) * 3600.
else
hour = integer( substring(string,1,2) ) * 3600.

if error-status:error then
return "bad":u.

val = hour + min + sec.

return "good":u.
/* end proc */
 
Top