Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Time from DateTime field 1

Status
Not open for further replies.

palock

MIS
Dec 19, 2005
3
0
0
US
I need to print just the Date of Birth from a DateTime field and eventually calculate the Age. I tried the formula from a Trim Number post, but it is not working - says that I need a string or array.

Any suggestions?
Thanks!
 
Thank you Durango - that site is wonderful. Unfortunately it does not have a way to strip the time off of the Date of Birth - it seems as if this should be fairly simple, but I am having a tough time...I am new to CR and may not quite have the hang of it yet.
Palock
 
Just change Ken's formula by wrapping the datetime with date():

WhileReadingRecords;
DateVar Birth:= date({ages.Birth}); // Replace this with your field for Date Of Birth
DateVar Ann := {ages.DateAnn}; // Replace this with CurrentDate to get their age as of the time of the report
//or the date field of an event to get their age as of the time of that event.
if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth)
then Year (Ann) - Year(Birth)
else Year (Ann) - Year(Birth) -1

-LB
 
If you are trying to print a single field, just right click Format Field. You can choose from a variety of date and/or time combinations.

As far as age goes, it is surprising that there still isn't a good built-in function. Here is a custom function I made.

Code:
Function  (DateTimeVar dstart, DateTimeVar dend)
// Returns number of year between two input dates
// Apparently there is no issue with DateAdd when subtracting years off of leap day
//  , so no need to isDate...

if DateAdd ('yyyy', -(DateDiff ('yyyy',dstart ,dend )), dend) >= dstart
    then DateDiff ('yyyy',dstart ,dend )
    else DateDiff ('yyyy',dstart ,dend )-1

or you put in a function and replace dstart and dend with your desired variables.

hth,
damon
 
Thank you all for your help - forest for the trees syndrome! I am off and running now and will play with both age calcs...
Palock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top