-2

I have a data set which containing 2 columns with dates with the following formats:

"2027-02-20 00:00:00 CET"    and "2014-12-31 CET"

how can I calculate the difference between these two dates? Or, how can I apply difftime ?

Here is a useful discussion but I cannot apply it directly?!

I gave by myself the link (above see: Here is blue) where one can find a very similar problem but not exact the same. Unfortunately some of people do not read the question carefully. Just one gave a useful hint. One dose not need any string manipulation!

Community
  • 1
  • 1
maniA
  • 1,437
  • 2
  • 21
  • 42
  • 1
    What did you try so far? –  Nov 16 '15 at 12:55
  • I guess I have to apply string manipulation at first! I am still working on it – maniA Nov 16 '15 at 13:00
  • @Pascal did you check the link which I mentioned?! – maniA Nov 16 '15 at 13:07
  • 2
    Read `help("strptime")`. No string manipulation is required to parse datetimes. – Roland Nov 16 '15 at 13:08
  • You could also search: place `[r] parse date` or `[r] strptime` in the search box above. – Dirk Eddelbuettel Nov 16 '15 at 13:10
  • Having read the link you provided you should be able to solve your problem as everything is explained in the answers. – etienne Nov 16 '15 at 13:11
  • Duplicate of [this question](http://stackoverflow.com/questions/33732686/find-amount-of-days-between-2-dates-in-php/33732753?noredirect=1#comment55241148_33732753) – Can O' Spam Nov 16 '15 at 13:32
  • Oh thanks @SamSwift I did not check it unfortunately but anyway thanks! – maniA Nov 16 '15 at 13:35
  • @maniA, I must apologise for a mistake on my part, the question I tagged was for PHP where yours is R, please ignore that comment! Apologies again! – Can O' Spam Nov 16 '15 at 13:36
  • @SamSwift better than some aggressive comments ;) no worries and thanks for your time anyway! – maniA Nov 16 '15 at 13:40
  • 1
    Possible duplicate of [Get the difference between dates in terms of weeks, months, quarters, and years](http://stackoverflow.com/questions/14454476/get-the-difference-between-dates-in-terms-of-weeks-months-quarters-and-years) – Jaap Nov 16 '15 at 14:00

1 Answers1

1

I solved my problem, the hint of Roland was really useful. I did not really need any string manipulation. If I apply

difftime(strptime("2027-02-20 00:00:00 CET", format = "%Y-%m-%d"),
         strptime("2014-12-31 CET", format = "%Y-%m-%d"),units="weeks")

it works well.

maniA
  • 1,437
  • 2
  • 21
  • 42