Skip to content

VFP: Create Datetime

Foxpro convert date and time to DateTime variable

By jasperdg on Mar 13, 2008

On the net some silly, unusable answers have been posted where programmers just concatenate DTOC() and DATE(). This is wrong! The DTOC() function depends on local date settings, thus resulting string of characters can not be predicted.

That’s why I had to create this little function:

FUNCTION DTtoDateTime(ldDate,lcTime)
 RETURN DATETIME(YEAR(ldDate),MONTH(ldDate),DAY(ldDate),;
        VAL(LEFT(lcTime,2)),VAL(RIGHT(lcTime,2)))
ENDFUNC 

This function is independent to local date and time settings.

Leave a Reply

Your email address will not be published. Required fields are marked *