Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7043445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:17:25+00:00 2026-05-28T02:17:25+00:00

I have a datetime string like so: > mydatetime [1] 2012-01-07 14:53:52 EST 2012-01-07

  • 0

I have a datetime string like so:

> mydatetime
 [1] "2012-01-07 14:53:52 EST" "2012-01-07 07:57:03 EST"
 [3] "2012-01-07 17:42:28 EST" "2012-01-08 10:28:35 EST"
 [5] "2012-01-08 10:37:22 EST" "2012-01-09 08:12:00 EST"
 [7] "2012-01-09 08:11:44 EST" "2012-01-09 17:45:24 EST"
 [9] "2012-01-09 14:28:22 EST" "2012-01-09 13:14:38 EST"

I’d like to separate the date and time into separate objects. I can get date successfully as:

> as.Date(mydatetime)
 [1] "2012-01-07" "2012-01-07" "2012-01-07" "2012-01-09" "2012-01-08"
 [6] "2012-01-08" "2012-01-08" "2012-01-09" "2012-01-09" "2012-01-09"

How can I extract the time portion? My goal is to plot date on the y-axis and time on the x-axis, to show a timelime of each day. Seems like the plot function requires special formats, so strings won’t work here. Any recommendations on timeline-esque plotting functions are appreciated as well. Thanks!

UPDATE

Simon’s answer below worked for me. However, I had to pull the date substring from mydatetime first, then use as.Date.

date <- as.Date(substr(mydatetime, 0,10))

For some reason it was five hours off. For example, 2012-01-09 19:05:21 EST would be converted to 2012-01-10. My timezone settings seem fine, and putting that string into as.Date directly gave 2012-01-09. No problem, I’m happy with this solution. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:17:26+00:00Added an answer on May 28, 2026 at 2:17 am

    There are several ways — either you treat it as a string:

    time = as.POSIXct(substr(mydatetime, 12,19),format="%H:%M:%S")
    plot(time, as.Date(mydatetime))
    

    or you compute on the dates:

    time = .POSIXct(as.numeric(as.POSIXct(mydatetime)) %% 86400)
    plot(time, as.Date(mydatetime))
    

    There is a subtle difference in the resulting plot ranges.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have date and time in a string formatted like that one: 2011-03-21 13:26
I have a date/time string that looks like the following: Wed Sep 21 2011
I have a serialized DateTime string which looks like this: 2010-04-14T16:32:06.75+10:00 What is the
I have datetime strings that look can like any the following: 1 13 2009
I have an MVC Action..... [HttpPost] public ActionResult DoStuff(string myString, DateTime myDateTime) ...and I'm
I have datetime data in string format like this: Sat Mar 24 23:59:59 GMT
Hello I have an unusual date format that I would like to parse into
I'm trying to convert a string into a date format My string looks like
I have a string like this: 250920111414 I want to create a DateTime object
i have two datetime string like this '2010-08-31 04:35:50.176725' and '2010-09-05 04:35:50.176725' . now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.