Solved
Contributor
Posts: 47

# convert 2 vars (char type) to 2 vars (date type)

I have 2 vars (char type):

date 1           date 2

26/07/2013   10/04/2014 07:50:11 p.m.
28/02/2013   12/09/2012 12:46:29

I need to convert to data type, how can I do it?

Accepted Solutions
Solution
‎03-02-2017 12:08 PM
Super User
Posts: 6,939

## Re: convert 2 vars (char type) to 2 vars (date type)

Your problem description talks about dates, and not datetimes.  To get dates only, you could use:

date_1_converted = input(date1, ddmmyy10.);

date_2_converted = input(date2, ddmmyy10.);

format date_1_converted date_2_converted yymmdd10.;

There's no need to apply YYMMDD10 as the final format.  That's just an example of what is possible.

Also note, it's not 100% clear that DATE_2_CONVERTED should apply the DDMMYY10 informat to convert it.  That would be applicable when the character values actually include the day then the month then the year.  But it's also conceivable that the character values contain the month then the day then the year.  In that case, convert with:

date_2_converted = input(date2, mmddyy10.);

All Replies
Super User
Posts: 24,027

## Re: convert 2 vars (char type) to 2 vars (date type)

Use the INPUT function.

NEW_VAR = INPUT( old_var_name, current_format);

Solution
‎03-02-2017 12:08 PM
Super User
Posts: 6,939

## Re: convert 2 vars (char type) to 2 vars (date type)

Your problem description talks about dates, and not datetimes.  To get dates only, you could use:

date_1_converted = input(date1, ddmmyy10.);

date_2_converted = input(date2, ddmmyy10.);

format date_1_converted date_2_converted yymmdd10.;

There's no need to apply YYMMDD10 as the final format.  That's just an example of what is possible.

Also note, it's not 100% clear that DATE_2_CONVERTED should apply the DDMMYY10 informat to convert it.  That would be applicable when the character values actually include the day then the month then the year.  But it's also conceivable that the character values contain the month then the day then the year.  In that case, convert with:

date_2_converted = input(date2, mmddyy10.);

🔒 This topic is solved and locked.