Extracting the hour from a date

Zack Vlliet

I have a date in a semi-odd format. It's written like:

Tue Oct 11 20:56:33 +0000 2016

The date is a string. The date shows what time and day a tweet was sent as in a data set. I want to find what hour each of my tweets were sent out. What is the best way to work with this? Is there a way to convert it to a date type easily, or is there a way to work with that string with what I want to do? Obviously I'd like to something like:

format(strptime(testTweets$Date, format = "%m %d %H:%M%S %Y", "%H"))

But I'm not sure how to work with the day of the week or the +0000. Thanks for the help!

Tim Biegeleisen

The above comment beat me to it, but try the following code:

strptime(x, format = "%a %b %d %H:%M:%S %z %Y")

[1] "2016-10-11 20:56:33"

You only need to check the documentation for strptime to figure out the correct format mask to use:

https://www.rdocumentation.org/packages/base/versions/3.4.3/topics/strptime

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related