I'm reading from an oracle database a date in this format: dd/mm/yyyy HH24:mi:ss.
when i write a query i have to write the whole date with seconds and minutes.
i need a way to write a query without giving this HH24:mi:ss.
how can i enter a date like 4/7/2011 and get it in this format dd/mm/yyyy HH24:mi:ss
this is the query:
q = "select * from MPOS t where t.TRANSACID='" + n +
"'and t.REPORTDATE between to_date('" + st + "', 'dd/mm/yyyy HH24:mi:ss')"
+ " and to_date('" + end + "', 'dd/mm/yyyy HH24:mi:ss')";
where st and end are DateTime
try use ToShortDateString():
q = "select * from MPOS t where t.TRANSACID='" + n +
"'and t.REPORTDATE between to_date('" + st.ToShortDateString() + "', 'dd/mm/yyyy')" +
" and to_date('" + end.ToShortDateString() + "', 'dd/mm/yyyy')";
I think you will also have to change the order of dd and mm so it would be 'mm/dd/yyyy'
Related
I am trying to construct this string for printing one message.
"At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(',');
from watch is VsCode:
where index =0;_subIndex =0;telNum.TelephoneDeviceType =Mobile;telephoneEnum=["Mobile","Landline"];
It's returning :
At position #[0][0] TLPHN_DVC_TYP NaN ,allowed Mobile,Landline
Full Code:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) > 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}
the condition should not satisfy but not sure why it's going inside the if and NaN returning. any suggestion?
It's the two plus signs: "] TLPHN_DVC_TYP " + + _telNum?// ...etc. The second one is parsed as the unary +, or a conversion to number, which obviously fails. Compare:
console.log("foo" + "bar");
console.log("foo" + + "bar");
Added #1:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) >= 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +_telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}
I have just upgraded from Xcode 8.3 to Xcode 9.4 and it kept indexing until it crashed, then it output an error.
Swift - Expression was too complex to be solved in reasonable time;
consider breaking up the expression into distinct sub-expressions
Is this a bug in Xcode 9 and Swift 4.1?
let fromString = convenience.getTimeAsString(timeStamp: timeStampDateAndTime, timeFormat: "HH:mm")
let toString = convenience.getTimeAsString(timeStamp: toTimeStamp, timeFormat: "HH:mm")
var cellData = "Booking: " + booking.BookingNumber + "\n" + "Area: " + booking.Locality + "\n" + "Postcode: " + booking.PostCode + "\n" + "Time: " + fromString + " - " + toString
How I fixed it?
var cellData = " \("Booking: ") \(booking.BookingNumber) \("\n") \("Area: ") \(booking.Locality) \("\n") \("Postcode: ") \(booking.PostCode) \("\n") \("Time: ") \(fromString) \(" - ") \(toString) "
How can I format this String with double x,y,total to two decimal places. String output = (x + " + " + y + " = " + total);
String ouput = String.format("%.2f + %.2f = %.2f",x,y,total);
System.out.println(output);
will give you the output with 2 decimal places or you can use DecimalFormat as well.
rs = s.executeQuery("SELECT Class1_predicted, Class2_predicted, Class3_predicted, Class_predicted"
+ SUM(PROFIT_LOSS) AS "Total Profit",
+ "FROM xxxxxx "
+ "WHERE CLASS1_PREDICTED = curr_class1_predicted, CLASS2_PREDICTED = curr_class2_predicted, CLASS3_PREDICTED = curr_class3_predicted, CLASS_PREDICTED = curr_class_predicted,"
+ "PROFIT_LOSS >= 0,"
+ "GROUP BY Class1_predicted, Class2_predicted, Class3_predicted,Class_predicted");
rs.next();
int recordCount = rs.getInt(1);
myConsole.getOut().println("Number of records in subset of table xxxxx where P/L >= 0: " + recordCount);
I am getting an error on the AS in the second line ?
Not sure how to correct ?
Bob M
You should put the whole query in a String.
It seems like here you are not actually quoting the expression:
+ SUM(PROFIT_LOSS) AS "Total Profit",
It should be something like this:
+ "SUM(PROFIT_LOSS) AS Total_Profit,"
I encounter an annoying issue with Android studio. I have nicely and easy readable formatted piece of code:
But if I press Code - reformat code, my string declaration turns in complete mess:
It would not be a problem if only new line characters were removed, but Code - reformat code also split my strings and make empty line insertions (WTF)
Compare string before reformat:
private static final String
DATABASE_CREATE =
"create table "
+ TABLE_NAME + "("
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_ITEM_ID + " integer default '0', "
+ COLUMN_SLUG + " text default '',"
+ COLUMN_TITLE + " text default '',"
+ COLUMN_TYPE + " integer default '0', "
+ COLUMN_YOUTUBE_ID + " text default '',"
+ COLUMN_ARTISTS + " text default '',"
+ COLUMN_ARTISTS_SLUG + " text default '',"
+ COLUMN_DESCRIPTION + " text default '',"
+ COLUMN_PICTURE + " text default '',"
+ COLUMN_SOURCE + " text default '',"
+ COLUMN_VIEW_COUNT + " integer '0',"
+ COLUMN_GOOGLE_LINK + " text default '',"
+ COLUMN_OFFLINE_SOURCE + " text default '',"
+ COLUMN_IS_SAVED_OFFLINE + " integer '0', "
+ COLUMN_OFFLINE_PLAYS + " integer default '0',"
+ COLUMN_DOWNLOADING_ID + " integer default '-1',"
+ COLUMN_IS_LIKE + " integer default '0' " +
");";
and string after reformat:
private static final String
DATABASE_CREATE =
"create table " + TABLE_NAME + "(" + COLUMN_ID + " integer primary key autoincrement, " +
"" + COLUMN_ITEM_ID + " integer default '0', " + COLUMN_SLUG + " text " +
"default ''," + COLUMN_TITLE + " text default ''," + COLUMN_TYPE + " integer " +
"default '0', " + COLUMN_YOUTUBE_ID + " text default ''," +
"" + COLUMN_ARTISTS + " text default ''," + COLUMN_ARTISTS_SLUG + " text " +
"default ''," + COLUMN_DESCRIPTION + " text default ''," +
"" + COLUMN_PICTURE + " text default ''," + COLUMN_SOURCE + " text default " +
"''," + COLUMN_VIEW_COUNT + " integer '0'," + COLUMN_GOOGLE_LINK + " text " +
"default ''," + COLUMN_OFFLINE_SOURCE + " text default ''," +
"" + COLUMN_IS_SAVED_OFFLINE + " integer '0', " + COLUMN_OFFLINE_PLAYS + " " +
"integer default '0'," + COLUMN_DOWNLOADING_ID + " integer default '-1'," +
"" + COLUMN_IS_LIKE + " integer default '0' " +
");";
You clearly can see lots of "" which were not present before.
How to fix such strange behaviour?