All,
I want to do a date subtract operation in Xquery, OSB 12C.Basically, have to check if an input date is < 6 months from the system date.
i.e- how to do in xquery : (SystemDate - inputDate) < 6 months
Have went through:
https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqdtopref.html but not able to compile any of the function listed there. Have also added the namespace in xquery. Do I need to add any library.
Any pointer is highly appreciated.
OSB has some extensions for dates, which you can read about here.
But, you might not even need that for simple stuff like you mentioned.
All,
Issue got resolved.Please find the link for the logic:http://developer.marklogic.com/pipermail/general/2015-February/016462.html
Subtracting dates give you dayTimeDuration in XQuery.
Following code is a simple and accurate way to check time intervals.
days-from-duration(fn:current-date() - $inputDate) < 180
180 is number of days you need to validate.
Related
I am trying to get week number for a given date. But its working for few dates and not working for couple of dates.
Followed this link https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
select from_unixtime(unix_timestamp('2015-12-31','yyyy-MM-dd'),'w') week_in_year;
The above code is returning 1
select from_unixtime(unix_timestamp('2016-12-31','yyyy-MM-dd'),'w') week_in_year;
The above code is returning 53. I think the first code snippet also should give something like 53/52. Any help is appreciated in solving.
I have a string as YYYY-MM-DD:HH:mm:SS:sss (ex : 2017-10-11:04:36:26.376). Now I want to convert it into epoch time . What would be programmatic approach for this ?
I am programming in C++, able to extract information in variable.
It turns out there is a formula, but it's fairly ugly. I originally implemented something similar in BASIC 2.0 in 1982 (when each byte counted), and later converted it to Perl:
sub datestar {
$_=shift;
/^(....)(..)(..)/;
$fy=($1-($2<3));
$jd=$fy*365+int($fy/4)-int($fy/100)+int($fy/400)+int(((($2-3+12*($2<3))*30.6)+.5)+$3);
return(86400*($jd-719469))
}
Note that this takes something like "20171011", not "2017-10-11", and doesn't convert hours/minutes/seconds (which are easy to convert).
As always, doublecheck code before use, and use it as a template to write your own code if you really want to.
However, you would be infinitely better off using your programming language's existing functions to do this.
As others said the formula is so complex and would make whole code a mess, So to avoid these I am calculating the number of days from Input date to 01-01-2000. As I know epoch time till 01-01-2000, thus by finding number of days considering leap year I can calculate total epoch time.
I love using dplyr; I use it for everything. But, the problem I'm experimenting today is the following:
I'm trying to simply filter all rows fromm my opps table where opp_date is from today. So, when I use filter(opps, as.Date(opp_date) == Sys.Date()) it's bringing today's data but also yesterday's too, from 19:00:00 onwards.
To clarify any possible problem:
opp_date field is POSIXct class
Sys.Date() returns correctly my current date and time (just to check, Sys.time() brings the correct time and date: "2017-07-21 10:06:04 COT")
Any idea here? Thanks to the community for all the great inputs :)
The issue must be due to different time-zones; by default, R uses your system's local time-zone.
Try to explicitly set the environment variable as follows:
Sys.setenv(TZ='UTC')
Cannot add a comment due to low repputation, so posting this as an answer.
As I got to know recently, R dates are a formatting nightmare, especially through the base functions. Checkout lubridate package. You may want to convert your date column using dmy_hms function. It's easy and vectors are supported by default. Try it and let me know if the problem persists.
And please always try to provide sample data. Otherwise people cannot reproduce your problems.
I have a date in this format {Y,M,D}. Is there any good supporting libraries or, tricks I can use to simply, say subtract three months from this date without running into problem with invalid dates, leap years, etc.
My latest similar use is in MySql where you can type:
Select '2011-05-31' - Interval 3 Month;
which yields '2011-02-28'. I am not interested in how to write this library myself, that is what I would like to avoid.
1> calendar:gregorian_days_to_date(calendar:date_to_gregorian_days({2011, 7, 14}) - 90).
{2011,4,15}
http://www.erlang.org/doc/man/calendar.html
Use edate - specifically the shift function.
> edate:shift({2011,5,31}, -3, months).
{2011,2,28}
Under the hood it uses the calendar module, so it correctly deals with all of the corner cases.
I created a GitHub gist with some useful utilities for this sort of thing. Feel free to steal from it if you want.
https://gist.github.com/104903
I am working on a project that involves converting data into dos date and time. using a hex editor (Hex Workshop) i have looked through the file manually and and found the values I am looking for, however I am unsure how they are calculated. I am told that the int16 value 15430 corresponds to the date 06/02/2010 but i can see no correlation, also the value 15430 corresponds to the time 07:34:12 but i am lost in how it is calculated. any help with these calculations would be very welcomed
You need to look at the bits in those numbers.
See here for details:
http://www.vsft.com/hal/dostime.htm
I know this post is very old but I think the time 07:34:12 corresponds to 15436 (not 15430).