I have, per cell, a date value in the format 2013-01-05 11:21.
Is there a way to separate the time of day (ie 11:21) and put it in a new column, without having to manually cut and paste?
I have a lot of date values in one column, and I want to separate the time-of-day portion of these dates into a new adjacent column.
Yes - the TIMEVALUE function should do this. You may need to format the result cells (in my examle: B1:B8) as time values. Using cell formatting, you can set the output to a hh:mm syntax, too.
Related
I'm trying to calculate the difference in 2 dates / times. My problem is the each date and time is in a separate column (see screenshot). Following is the formula I have been using:
=IF(RC[-1]-RC[-4] =0,"",RC[-1]-RC[-4])
This worked until the 2 date columns weren't the same day.
I'm having trouble trying to combine the dates and time within the formula. I could write a macro to do this or I could combine each date and time paring into one column if that makes it easier. I'd rather not combine them as separate columns is easier for the user base.
Any help or suggestions would be greatly appreciated. Thanks in advance for your help....
First concatenate the Date and Time
=concatenate(text(A2,"mm/dd/yyyy")&" "&text(B2,"hh:mm:ss"))
then
subtract them
Other wise look at this. You can direct Subtract the dates and time without adding any extra columns
enter image description here
=(CONCATENATE(TEXT(C2,"mm/dd/yyyy")&" "&TEXT(D2,"hh:mm:ss AM/PM"))-CONCATENATE(TEXT(A2,"mm/dd/yyyy")&" "&TEXT(B2,"hh:mm:ss AM/PM")))*24
File Reference
I have a dataframe with a date column. These dates represent the date that a particular poll result was actually taken. However, the website takes these results and adds them to a table not necessarily on the date of the poll taking. So for example:
20/01/2018
21/01/2018
20/01/2018
19/01/2018
so the date at the top (20/01/2018) came in after the ones below. But the poll below says 21st and thats the date that the poll was taken so the earliest date that the one above could have been added is the 21st thus the list becomes;
21/01/2018
21/01/2018
20/01/2018
19/01/2018
and now my column is sorted. I need to do this for like 50 variables! Suggestions?
I want to sort my dates column such that if i go from bottom to top of the column if a date has a later date below it, then that date becomes that later date too.
enter image description here
Maybe there is a prettier way, but this should give the desired output:
data$Date <- as.POSIXct(rev(cummax(rev(as.numeric(data$Date)))), origin = "1970-01-01")
The idea is that you want a rolling maximum from the bottom up, for example once the 2018-01-02 was reached, the rows above can not have a date that is "smaller" than the 2018-01-02. This is done by the cummax function. It carries the maximum date reached and overwrites earlier/smaller dates. Since you want it to go from the bottom up, you have to reverse your date column via rev and then reverse it back after your call of cummax. Because cummax only works for numeric input I transformed your date column to numeric and back to date in the end.
I have a vector that contains time data, but there's a problem: some of the entries are listed as dates (e.g., 10/11/2017), while other entries are listed as dates with time (e.g., 12/15/2016 09:07:17). This is problematic for myself, since as.Date() can't recognize the time portion and enters dates in an odd format (0012-01-20), while seemingly adding dates with time entries as NA's. Furthermore, using as.POSIXct() doesn't work, since not all entries are a combination of date with time.
I suspect that, since these entries are entered in a consistent format, I could hypothetically use an if function to change the entries in the vector to a consistent format, such as using an if statement to remove time entirely, but I don't know enough about it to get it to work.
use
library(lubridate)
Name of the data frame or table-> x
the column that has date->Date
use the ymd function
x$newdate<-ydm(x$Date)
I created a data table called ltfs from a table I loaded in through a ODBC connection that was named ltfs
ltfs<-data.table(ltfs)
In this table there is a column with a date field in it. When I check the class of that column it returns "POSIXct" "POSIXt". When I check what the dates look like they are in the form of ex. 2014-01-01. I am trying to count the number of entries with a date in this field less than a certain date. I tried using the .N feature but am getting an error that has to do with the way the date formats are. My code is below any help would be much appreciated.
ltfs<-data.table(ltfs)
datecount<-ltfs[Eligibility_Date<=as.Date("2011-01-01"),.N]
I know it has to do with the date format (either the criteria or the format of the dates in the table) just not sure how to handle them.
I have a column of data in the form of a string, and I need to change it to date because it is a time series.
200612010018 --> 2006-12-01 00:18
I've tried unsucessfully,
strptime(200612010018,format ='%Y%M%D %H:%MM')
After doing this I need to append one data set to another one.
Will I have any problems using rbind() if the column contains dates?
Thanks
You were close. You mixed minutes(%M) and months (%m). And the the format argument needs to follow the format you provide.
strptime(200612010018,format ='%Y%m%d%H%M')
#"2006-12-01 00:18:00