I required date as mentioned below in if condition.
if day('2019-12-23') <=15 then '2019-11-16' else '2019-12-01'.
I have tried writing codes in R, but output is not correct.
Codes
ifelse(day(Sys.Date()) <=15,
(ymd(Sys.Date()-day(Sys.Date()-1)) %m-% months(1))+15,
ymd(Sys.Date()-day(Sys.Date()-1)))
Output
18231
Required Output
2019-12-01
Please help me with the solution.
Got the solutions thanks. forgot to convert into character.
updated query
ifelse(day(Sys.Date()) <=15,
as.character((ymd(Sys.Date()-(day(Sys.Date()-1))) %m-% months(1))+15),
as.character(ymd(Sys.Date()-(day(Sys.Date()-1)))))
Related
I am trying to convert AM/PM formatted date and time into as.posixct , but for every 00:00:00 , i am getting NA. please guide me on this. please refer below image.
CODE I TRYED WITH FOR LOOP
i=0
for (i in 1:nrow(clean_df)){
if((is.na(clean_df$Local_time)[i]) == TRUE){
#cat("",clean_df$Local_time[i])
clean_df$Local_time[i] <- paste("",as.Date(clean_df$Local_time[i-1]),"00:00:00")
}
print(nrow(clean_df)-i)
}
But above code is taking longer time to execute , which is not recommended . requesting you all any solution with this.
Given that some of your raw data may be lacking a time component, when you expect it to be present when converting to POSIXct, I don't see any way around scrubbing your data. But, you may try doing the scrubbing in a vectorized way, which might perform better:
clean_df$Local_time <- ifelse(nchar(clean_df$Local_time) == 10,
paste(clean_df$Local_time, "00:00:00"),
clean_df$Local_time)
Say I have a string of date like "3/23/2016" and just want to change the format to 3/23/2016. I try:
as.Date("3/23/2016, "%m%d%Y") but keeps giving me NA, as well as trying other methods. Anyone know a easy/fast way to do this? 03/23/2016 is ok too.
Try this:
b=as.Date(a, "%m/%d/%Y"),
It will give you the result then
Try:
Class(b)
to find the format.
Hope this helps :)
Another option is lubridate
library(lubridate)
mdy("3/23/2016")
#[1] "2016-03-23"
I am currently writing a block of code on R which collects data via a SPARQL query. My problem is when I am trying to filter the query by date, R gives an error of "unexpected numeric constant".
There is no any mistake in the SPARQL code because when I run the exact code on the endpoint I receive data normally.
You will find the block of code where I have the problem. It does not matter the lines before and after, just the second line of the date filter.
...
OPTIONAL {?seller gr:legalName ?sellerLegalName} .
FILTER REGEX (STR(?date) >= "2015-01-01") .
FILTER NOT EXISTS {?spendingItem elod:hasCorrectedDecision ?correctedDecision} .
...
Please, I would kindly ask for your help! :)
For any further information that you want in order to solve the problem, feel free to contact with me.
Thank you all!!!
SOLVED!
I found that the date should be passed as timestamp!
Also, I found a useful site where you can convert any date in timestamp and vice versa.
I would like to thank you all for your responses and your useful help!
You should filter it as a date/time value rather than as a string - perhaps that will help:
FILTER (?date > "2015-01-01"^^xsd:date)
See this answer: SPARQL date range
i have date showing like the following
01-Nov-2012 12:00:00 AM
and i want to show the if the date is like above than
01-Nov-2012
this comes for few data only not for all,
How to do this in Xquery.
Please help
Regards
This will work:
fn:replace("01-Nov-2012 12:00:00 AM", "\s.*", "")
It replaces the space and everything after with the empty string.
You could use either:
tokenize(/test,' ')[1]
or
substring-before(/test,' ')
With /test being replaced with the appropriate path to the date.
It is so simple.
convert(VARCHAR(10),datetoformate,106)
thats it
How do I compare two dates in Lingo? To be specific, I want to know if today's date is after some fixed date. I know I can create the fixed date by using:
date("20090101")
and I can get the current date using:
_system.date()
but I can't seem to directly compare the two. Do I have to parse the _system.date() to determine if it's after my fixed date? I tried:
if(_system.date() > date("20090101") then
--do something
end if
but that doesn't seem to work. Any ideas?
Instead of _system.date(), try _movie.systemDate(), it will return a date object that you can safely compare with another one.
if _movie.systemDate() > date("20090101") then
--do something
end if
regards
I ended up doing the following. Inelegant, but it works:
if (_system.date().char[1..2] >= 01 and _system.date().char[4..5] >= 01 and _system.date().char[7..10] >= 2010) then
alert("Your license has expired. Please contact the Company to renew your license.")
_player.quit()
end if
It does the trick, but I would still be interested in alternative methods of doing this.