Desktop productivity for business analysts and programmers

character to date variable

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 340
Accepted Solution

character to date variable

can i please get help on this,

 

wants to convert below character value to date value 

 

Have 

char_var=2015.09.19 /*sorry but this is character value that i ended up by pulling it out from long string)*/

 

want

date_var=09192015 /*want it as a date*/

 

 

thank you in advance,

 


Accepted Solutions
Solution
‎10-02-2015 04:13 PM
Trusted Advisor
Posts: 1,795

Re: character to date variable

[ Edited ]

date_Var=mdy(scan(char_var,2,'.')+0,scan(char_var,3,'.')+0,scan(char_var,1,'.')+0);

format date_Var mmddyy8.;

View solution in original post


All Replies
Solution
‎10-02-2015 04:13 PM
Trusted Advisor
Posts: 1,795

Re: character to date variable

[ Edited ]

date_Var=mdy(scan(char_var,2,'.')+0,scan(char_var,3,'.')+0,scan(char_var,1,'.')+0);

format date_Var mmddyy8.;

Super User
Posts: 5,368

Re: character to date variable

While I can't test this at the moment, you should be able to read the character string directly:

 

date_var = input(char_var, yymmdd10.);

 

That will give you the proper date value.  For display purposes, choose the date format that you would like.  To match the result you originally asked for:

 

format date_var mmddyyn8.;

 

Good luck.

Super Contributor
Super Contributor
Posts: 340

Re: character to date variable

 

 

Super User
Posts: 19,167

Re: character to date variable

date_want=input(date_have, anydtdte10.);
format date_want date9.;

This works for me. 

Super Contributor
Super Contributor
Posts: 340

Re: character to date variable

Yes Reeza that worked, thanks

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 365 views
  • 1 like
  • 4 in conversation