- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Someone passed me date variables like that follows. Both Finished_date (Char 15 $15. $15.) and Start_date (Char 10 ) are characters.
I'd like to compute difference in days between Finished_date and Start_date; that is, Diff_days = Finished_date - Start_date, but it does not work. How can I do this simple subtraction? convert character to date format first?
Thank you very much for your help! Lee
Finished_date Start_date
2/15/2020 10/15/2018
2/15/2020 3/1/2018
2/15/2020 7/8/2018
2/16/2020 9:28 8/20/2019
2/16/2020 12:44 1/1/2017
2/17/2020 0:10 9/25/2016
2/17/2020 7:54 10/15/2019
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would play it safe and go with :
diff_days = input(scan(finished_date, 1, " "), mmddyy10.) - input(scan(start_date, 1, " "), mmddyy10.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Given that both are character variables, you have to convert from character to numeric on the fly, as part of the computation:
diff_days = input(finished_date, mmddyy10.) - input(start_date, mmddyy10.);
This assumes that the time values are part of FINISHED_DATE, not part of START_DATE. Even then, there could be complications if you have 8-character dates with a time piece like 2/6/2017 9:28. If that occurs, a slightly more complex formula would be needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would play it safe and go with :
diff_days = input(scan(finished_date, 1, " "), mmddyy10.) - input(scan(start_date, 1, " "), mmddyy10.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content