How to set date using OCCI::Date::setDate method - date

I am trying to create a OCCI::Date object using setDate method but I get an error while doing so.
Below is the snippet of my code.
using ODate = oracle::occi::Date;
ODate ts;
ts.setDate(datetime.year(),datetime.month(),datetime.day(),datetime.hour (),datetime.minute(),datetime.second());
this is the error I get - ORA-32146: Cannot perform operation on a null date
I also printed the values that I am passing to setDate method to check if those values are correct and they are all fine and within the Date range.
datetime.year() = 2018
datetime.month() = 6
datetime.day() = 5
datetime.hour() = 6
datetime.minute() = 1
datetime.seconds() = 22
Any leads to resolve this issue?

Oracle has its own format of storing date. Check this link.
Set the resulted value in OCIDate.OCIDateYYYY

Related

Problem with understanding date formats in googleScripts

I made a few functions with GoogleSheets using AppsScripts for simple task a few times in previous years. I always had problems when taking dates from cells/ranges and processing them, but somehow alwaays found a workaround, so that I did not have to deal with it. Well, this time I can not find a workaround, so I will try to explain my problems with the following code:
function getDates(){
var s = SpreadsheetApp.getActiveSpreadsheet();
var sht = s.getSheetByName('Dates');
var date = sht.getRange(2,1).getValues();
Logger.log(date[0][0]); //output is Tue Jun 08 18:00:00 GMT-04:00 2021
var datumFilter= Utilities.formatDate(date[0][0], "GMT+1", "dd/mm/yy");
Logger.log(datumFilter); //output is 08/00/21
var outrng = sht.getRange(25,1);
outrng.setValue(date);
}
The first targeted cell ('var date') has a value of "9.6.21" in the spreadsheet. The cell is formatted as a date and it opens a calendar when double-clicked. When I set the new cells values (with 'outrng.setValue(date);'), the result is OK, with the same date as in the original cell.
But I do not need to simply transfer the values, I want to implement them in some loops and I have no idea how to simply get the date in the same format or at least the same date in the script as it is in the cell. As you can see from the logger, the values there are different. A simple d/m/yy format would be sufficient.
My spreadsheet settings are set to my local time (Slovenia, GMT+1).
I am guessing that I am missing some basics here. I have spent many hours trying to understand it, so any help is highly appreciated!
Cooper already answered all your questions in the comment. I'd like to add on and show you an example on what it would like and add some modifications.
Code:
function getDates() {
var s = SpreadsheetApp.getActiveSpreadsheet();
var sht = s.getSheetByName('Dates');
// get last row of the sheet
var lastRow = sht.getLastRow();
// get your sheet's timezone
var timezone = SpreadsheetApp.getActive().getSpreadsheetTimeZone();
var output = [];
// getValues is mostly used for multiple cells returning a 2D array
// use getValue for single cells to return its actual value
// but since function name is getDates, I assume column A is all dates
// so we fetch the whole column (A2:A[lastRow]) except the header
var dates = sht.getRange("A2:A" + lastRow).getValues();
// for each date on that column, we format the date to d/M/yy
// m/mm = minute
// M/MM = month
dates.forEach(function ([date]){
Logger.log(date);
var datumFilter= Utilities.formatDate(new Date(date), timezone, "d/M/yy");
Logger.log(datumFilter);
// collect all dates in an array
output.push([datumFilter]);
});
// assign all the dates in the array onto range B2:B
sht.getRange(2, 2, output.length, 1).setValues(output);
}
Sample data:
Logs:
Output:
Note:
The output on sheets is not equal to logs due to the formatting of my sheet.

Initializing Date in Kotlin

I'm trying to pass a date to a function in Kotlin. I don't want to have to type "08/30/2018" as a String and would instead prefer Date. I initially tried just 08/30/2018 but get a compiler stating an Integer was found for the input rather than Date.
var myDate = 1/1/2000
var newDate = 08/30/2018
fun setDate(value: Int){
myDate = value
}
setDate(newDate)
println(newDate) //0
println(myDate) //0
println(myDate.compareTo(newDate)) //0
Why does Kotlin accept 08/30/2018 as an int? Why is it stored correctly to another int variable but then print 0 when the value is retrieved?
How can I initialize a variable to a date like 1/1/2000 and then set another date later on? I haven't found anything about passing a date anywhere unless it is a String.
When you assign 8/30/2018 to a variable then the compiler recognizes it as integer division 8/30 which is 0 and then /2018 and the result is 0.
You could do it like val date = Date("1/1/2000") but this is now deprecated
You can use the Java 8 Date/Time API instead:
val date = LocalDate.of(2000, 1, 1)
you can find more here:
https://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html

Trying to build Expression for Table field to sort text dates, some with missing elements

Hi I am a newbie and have a problem I have been trying to solve for weeks. I have a table imported from excel with dates in text format (because dates go back to 1700s) Most are in the format "mmmyyyy", so it is relatively easy to add "1" to the date, convert to date format, and sort in correct date order. The problem I have is that some of the dates in the table are simply "yyyy", and some are empty. I cannot find an expression that works to convert these last two to eg 1 Jan yyyy and 1 Jan 1000 within the same expression. Is this possible, or would I need to do this in two queries? Sorry if this question is very basic - I cannot find an answer anywhere.
TIA
You can do something like:
Public Function ConvertDate(Byval Expression As Variant) As Date
Dim Result As Date
If IsNull(Expression) Then
Result = DateSerial(1000, 1, 1)
ElseIf Len(Expression) = 4 Then
Result = DateSerial(Expression, 1, 1)
Else
Result = DateValue(Right(Expression, 4) & "/" & Left(Expression, 3) & "/1")
End If
ConvertDate = Result
End Function

how to check the date using internet in matlab?

when using date command in matlab, i get the system current date. is there a way to get the current date using internet in matlab? the link i've given is similar to this question but that question was asked for vb, and i'm trying to do this thing in matlab.
https://stackoverflow.com/questions/21198527/how-to-check-the-real-date-time-through-an-internet-connection]
MATLAB Code based on urlread to get current date using internet (URL) and with couple of bounding keys (to find the date string) -
URL = 'http://time.is/';
key1 = 'title="Click for calendar">';
key2 = '</h2>';
data = urlread(URL);
start_ind = strfind(data,key1);
data1 = data(start_ind:end);
off_stop_ind = strfind(data1,key2);
current_date = data(start_ind+ numel(key1):start_ind + off_stop_ind(1)-2)
Output at my location -
current_date =
Saturday, September 6, 2014, week 36
If you would like to have it in the DD-MM-YYYY format, use this -
date_split = strsplit(current_date,',')
current_date1 = datestr(strcat(date_split(2),date_split(3)))
Output -
current_date1 =
06-Sep-2014

select options with today's date as default?

I'm trying to show todays date as the default value in a select date.
INITIALIZATION.
select-OPTIONS: so_date FOR sy-datlo.
START-OF-SELECTION.
so_date-sign = 'I'.
so_date-option = 'BT'.
so_date-low = sy-datum.
so_date-high = sy-datum.
APPEND so_date.
This isn't working though. Any ideas?
You must set the value before START-OF_SELECTION:
select-OPTIONS: so_date FOR sy-datlo.
INITIALIZATION.
so_date-sign = 'I'.
so_date-option = 'EQ'.
so_date-low = sy-datum.
CLEAR so_date-high.
APPEND so_date.
Did you try the easy version:
select-OPTIONS: so_date FOR sy-datlo default SY-DATUM.
I think it should work (can't test is actual).