Hi I am trying to get dates after datetime('now)
My query is not checking against the time value.
I have the following dates :
2015-09-03 18:00:00
2015-09-03 18:00:00
2015-09-10 16:30:00
2015-09-13 09:00:00
2015-09-13 09:00:00
2015-09-13 09:00:00
2015-09-13 09:00:00
2015-09-13 09:00:00
2015-09-13 09:00:00
2015-09-13 09:00:00
2015-09-13 12:05:00
2015-09-13 12:05:00
2015-09-13 12:25:00
2015-09-13 12:25:00
2015-09-13 12:25:00
2015-09-13 16:30:00
2015-09-14 15:10:00
2015-09-14 18:20:00
It seems to ignore the time completely
I can get it to return anything after the 14th, i would expect it to return anything where the time is greater than my startdate (2015-09-14 12:40:39)
public function getRemainingKeysForTimeframe($timeframeID){
$startDate = new \DateTime('now');
$queryBuilder = $this->createQueryBuilder('q')
->select('q')
->andWhere('q.timeframeID = :timeframeID')
->andWhere('q.date >= :start')
->setParameter('timeframeID', $timeframeID)
->setParameter('start', $startDate->format('Y-m-d h:i:s'));
return $queryBuilder;
}
Inject the actual \DateTime object as a parameter in your query builder:
->setParameter('start', $startDate);
not
->setParameter('start', $startDate->format('Y-m-d h:i:s'));
Related
I want to update the year only to 2025 without changing the month day and time
what I have
2027-01-01 09:30:00
2012-03-06 12:00:00
2014-01-01 17:24:00
2020-07-03 04:30:00
2020-01-01 05:50:00
2021-09-03 06:30:00
2013-01-01 23:30:00
2026-01-01 08:30:00
2028-01-01 09:30:00
what i required is below:
2025-01-01 09:30:00
2025-03-06 12:30:00
2025-01-01 17:24:00
2025-07-03 04:30:00
2025-01-01 05:50:00
2025-09-03 06:30:00
2025-01-01 23:30:00
2025-01-01 08:30:00
2025-01-01 09:30:00
I am using dB Browser for SQLite
what i have tried but it didn't worked
update t set
d = datetime(strftime('%Y', datetime(2059)) || strftime('-%m-%d', d));
You may update via a substring operation:
UPDATE yourTable
SET ts = '2025-' || SUBSTR(ts, 6, 14);
Note that SQLite does not actually have a timestamp/datetime type. Instead, these values would be stored as text, and hence we can do a substring operation on them.
I want to substract timeA with timearriving and timeL with timeleaving but I get this error:
"Error in unclass(e1) - e2 : non-numeric argument to binary operator"
When you see that error message, it means that you're trying to perform a binary operation with something that isn't a number. I understand the error but I wanted to ask is there is a way I can perform these calculations?
I provided a sample image of my dataset
number id location timearriving timeleaving timeA timeL person late
1 214980 900264 1001.18 NULL NULL 2016-09-15 10:00:00 2016-09-15 12:00:00 Teacher
2 215708 900264 1001.18 07:55:06 09:59:58 2016-09-22 10:00:00 2016-09-22 12:00:00 Teacher
3 216388 900264 1001.18 08:00:22 09:54:06 2016-09-29 10:00:00 2016-09-29 12:00:00 Teacher
4 217106 900264 1001.18 08:40:15 09:53:07 2016-10-05 10:00:00 2016-10-05 12:00:00 Teacher
5 217250 900264 1001.18 08:03:47 09:52:59 2016-10-06 10:00:00 2016-10-06 12:00:00 Teacher
6 217808 900264 1001.18 NULL NULL 2016-10-12 10:00:00 2016-10-12 12:00:00 Teacher
7 217952 900264 1001.18 08:01:44 09:51:45 2016-10-13 10:00:00 2016-10-13 12:00:00 Teacher
8 218640 900264 1001.18 08:04:04 09:57:24 2016-10-19 10:00:00 2016-10-19 12:00:00 Teacher
9 218788 900264 1001.18 07:59:52 09:50:17 2016-10-20 10:00:00 2016-10-20 12:00:00 Teacher
10 219397 900264 1001.18 08:01:06 09:51:05 2016-10-26 10:00:00 2016-10-26 12:00:00 Teacher
11 219541 900264 1001.18 08:05:29 09:56:04 2016-10-27 10:00:00 2016-10-27 12:00:00 Teacher
12 220273 900264 1001.18 08:09:20 09:57:46 2016-11-02 09:00:00 2016-11-02 11:00:00 Teacher
13 220419 900264 1001.18 08:09:05 09:59:53 2016-11-03 09:00:00 2016-11-03 11:00:00 Teacher
Here I added a new column with the name "late".
I want to subtract TimeA- timearriving
I did this using this code:
dataset["late"] <- NA
dataset$late <- dataset$timeA - dataset$timearriving
then the error was:
Error in unclass(e1) - e2 : non-numeric argument to binary operator
Now I tried to convert them like you said:
timeA <- ymd_hms(timeA )
timearriving <- hms(timearriving )
Warning message:
In .parse_hms(..., order = "HMS", quiet = quiet) :
Some strings failed to parse
Since you don't provide a reproducible example I will illustrate using one value for each variable e.g.:
library(lubridate)
timeleaving <- hms("09:59:33")
timeA <- ymd_hms("2017-02-16 10:00:00")
You could use:
timeleaving <- ymd_hms(paste(floor_date(timeA, "days"), timeleaving))
dif <- timeA -timeleaving
Time difference of 27 secs
Edited since the data was added to the original question:
data$timeleaving <- hms(data$timeleaving)
data$timearriving <- hms(data$timearriving)
data$timeA <- ymd_hms(data$timeA )
data$timeL <- ymd_hms(data$timeL )
data$timeleaving <- ymd_hms(paste(floor_date(data$timeL, "days"), data$timeleaving))
data$timearriving <- ymd_hms(paste(floor_date(data$timeA, "days"), data$timearriving))
data$late <- data$timeA - data$timearriving
I think the endpoints are generated by converting the index to UTC. I want the endpoints at change of every hour 9:00/10:00 etc ( or at my specific defined intervals, say at 9:30/10:30 etc).
In the below example object 'a' is UTC and endpoints are created at 4:55,5:55 etc, for the object 'b' its at 10:25,11:25 etc. I am looking for a solution that gives endpoints in specified way, irrespective of timezone.
Is there any simple mechanism to do so?
> head(a)
Open High Low Close
2008-01-01 04:30:00 6114.05 6126.65 6111.35 6111.35
2008-01-01 04:35:00 6110.50 6130.65 6110.50 6128.90
2008-01-01 04:40:00 6128.70 6130.15 6123.15 6123.55
2008-01-01 04:45:00 6124.85 6131.90 6123.45 6131.55
2008-01-01 04:50:00 6132.20 6134.45 6128.70 6131.20
2008-01-01 04:55:00 6132.25 6134.85 6132.25 6134.45
> indexTZ(a)
TZ
"UTC"
> a[endpoints(a,on="hours")]
Open High Low Close
2008-01-01 04:55:00 6132.25 6134.85 6132.25 6134.45
2008-01-01 05:55:00 6136.70 6136.70 6132.15 6134.45
2008-01-01 06:55:00 6157.65 6157.65 6153.20 6154.25
2008-01-01 07:55:00 6155.65 6157.60 6155.00 6157.25
2008-01-01 08:55:00 6143.25 6143.90 6137.50 6138.05
2008-01-01 09:55:00 6150.95 6151.65 6147.50 6149.20
2008-01-02 04:55:00 6113.40 6120.90 6089.00 6089.00
2008-01-02 05:55:00 6086.15 6087.25 6068.80 6068.95
2008-01-02 06:55:00 6098.10 6108.25 6098.10 6105.85
2008-01-02 07:05:00 6107.40 6107.40 6093.70 6094.80
> head(b)
Open High Low Close
2008-01-01 10:00:00 6114.05 6126.65 6111.35 6111.35
2008-01-01 10:05:00 6110.50 6130.65 6110.50 6128.90
2008-01-01 10:10:00 6128.70 6130.15 6123.15 6123.55
2008-01-01 10:15:00 6124.85 6131.90 6123.45 6131.55
2008-01-01 10:20:00 6132.20 6134.45 6128.70 6131.20
2008-01-01 10:25:00 6132.25 6134.85 6132.25 6134.45
> indexTZ(b)
TZ
"Asia/Kolkata"
> b[endpoints(b,on="hours")]
Open High Low Close
2008-01-01 10:25:00 6132.25 6134.85 6132.25 6134.45
2008-01-01 11:25:00 6136.70 6136.70 6132.15 6134.45
2008-01-01 12:25:00 6157.65 6157.65 6153.20 6154.25
2008-01-01 13:25:00 6155.65 6157.60 6155.00 6157.25
2008-01-01 14:25:00 6143.25 6143.90 6137.50 6138.05
2008-01-01 15:25:00 6150.95 6151.65 6147.50 6149.20
2008-01-02 10:25:00 6113.40 6120.90 6089.00 6089.00
2008-01-02 11:25:00 6086.15 6087.25 6068.80 6068.95
2008-01-02 12:25:00 6098.10 6108.25 6098.10 6105.85
2008-01-02 12:35:00 6107.40 6107.40 6093.70 6094.80
>
Thanks & Regds
Siva Sunku
endpoints always calculates offsets in UTC. There's nothing you can do to change that as an end-user. But you could work-around it by comparing the 1-hour endpoints with the 30-minute endpoints.
x <- .xts(1:12, seq(0, by=600, length.out=12), tzone="Asia/Kolkata")
x[endpoints(x, "hours")]
# [,1]
# 1970-01-01 06:20:00 6
# 1970-01-01 07:20:00 12
hourEndpointsTZ30 <- function(x) {
h <- endpoints(x, "hours", 1)
m <- endpoints(x, "minutes", 30)
c(0, setdiff(m, h), last(m))
}
x[hourEndpointsTZ30(x)]
# [,1]
# 1970-01-01 05:50:00 3
# 1970-01-01 06:50:00 9
# 1970-01-01 07:20:00 12
I was working with a time series dataset having hourly data. The data contained a few missing values so I tried to create a dataframe (time_seq) with the correct time value and do a merge with the original data so the missing values become 'NA'.
> data
date value
7980 2015-03-30 20:00:00 78389
7981 2015-03-30 21:00:00 72622
7982 2015-03-30 22:00:00 65240
7983 2015-03-30 23:00:00 47795
7984 2015-03-31 08:00:00 37455
7985 2015-03-31 09:00:00 70695
7986 2015-03-31 10:00:00 68444
//converting the date in the data to POSIXct format.
> data$date <- format.POSIXct(data$date,'%Y-%m-%d %H:%M:%S')
// creating a dataframe with the correct sequence of dates.
> time_seq <- seq(from = as.POSIXct("2014-05-01 00:00:00"),
to = as.POSIXct("2015-04-30 23:00:00"), by = "hour")
> df <- data.frame(date=time_seq)
> df
date
8013 2015-03-30 20:00:00
8014 2015-03-30 21:00:00
8015 2015-03-30 22:00:00
8016 2015-03-30 23:00:00
8017 2015-03-31 00:00:00
8018 2015-03-31 01:00:00
8019 2015-03-31 02:00:00
8020 2015-03-31 03:00:00
8021 2015-03-31 04:00:00
8022 2015-03-31 05:00:00
8023 2015-03-31 06:00:00
8024 2015-03-31 07:00:00
// merging with the original data
> a <- merge(data,df, x.by = data$date, y.by = df$date ,all=TRUE)
> a
date value
4005 2014-07-23 07:00:00 37003
4006 2014-07-23 07:30:00 NA
4007 2014-07-23 08:00:00 37216
4008 2014-07-23 08:30:00 NA
The values I get after merging are incorrect and they contain half-hourly values. What would be the correct approach for solving this?
Why are is the merge result in 30 minute intervals when both my dataframes are hourly?
PS:I looked into this question : Fastest way for filling-in missing dates for data.table and followed the steps but it didn't help.
You can use the padr package to solve this problem.
library(padr)
library(dplyr) #for the pipe operator
data %>%
pad() %>%
fill_by_value()
I'm trying to compare the most recent value in a data frame, with the previous value and can't figure it out. Is there a tail command that returns the previous to last value??
I'm trying to return the value that was before the last bar;
2014-08-21 21:00:00 77.80724
tail(stock)
minutes.Close
2014-08-20 20:00:00 76.06327
2014-08-20 21:05:00 73.51396
2014-08-21 11:00:00 74.11548
2014-08-21 16:00:00 77.13998
2014-08-21 21:00:00 77.80724
2014-08-21 23:20:00 77.86165
tail(stock, n=1)
minutes.Close
2014-08-21 23:20:00 77.86165
Just do
head(tail(stock, n=2),1)
or
stock[nrow(stock)-1, ]