Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to convert a string to a date time object. The string looks like this
"2016-06-16T23:26:25.252Z"
I have been trying to convert it using DateTime.strptime(str,"'%Y-%m-%dT%H:%M:%S.%L%z") but gives invalid date error.
Do any of you know the issue?
Thanks!
You put an extra quotation mark in the string.
str = "2016-06-16T23:26:25.252Z"
DateTime.strptime(str,"'%Y-%m-%dT%H:%M:%S.%L%z") #=> ArgumentError: invalid date
DateTime.strptime(str,"%Y-%m-%dT%H:%M:%S.%L%z") #=> #<DateTime: 2016-06-16T23:26:25+00:00 ((2457556j,84385s,252000000n),+0s,2299161j)>
^^^
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to check if a specific element is included in an output. I run:
results.include? {"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100}
but I get an error:
Syntax error, unexpected =>, expecting '}'
What did I do wrong?
The problem is that the curly brackets in this case are interpreted as start of a block. Just put () around:
results.include?({"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100})
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm following the ruby on rails guide written by Micheal Harl. I"m wondering what ?('').?.? means in the code below.
def string_shuffle(s)
s.?('').?.?
end
string_shuffle("foobar")
# => "oobfra"
I think it should be replaced with methods, like bellow:
def string_shuffle(s)
s.split('').shuffle.join
end
def string_shuffle(s)
s.split('').shuffle.join
end
string_shuffle("foobar")
# => "oafrob"
It doesn't mean anything. It's a syntax error. That code is not legal Ruby.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am trying to convert the string "country." to a symbol. I expect to receive :country. including the point ..
I tried the following, but they do not work as my symbols still have quotes.
"country.".to_sym; #=> :"country."
"country.".intern; #=> :"country."
"country.".parameterize.underscore.to_sym; #=> :country
"country\.".to_sym; #=> :"country."
It's working as expected.
A symbol most of the time looks like:
:symbol_name
However when the symbol contains special characters such as spaces or hyphens, or in your case a period, it needs to be enclosed in quotes:
:"symbol name with-many special characters."
Although it doesn't look 'correct', it will act as any other symbol.
perhaps it will help you:
:'country.'
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I get an error NoMeathodError undefined method / for 15 with this code:
tts = gets.chomp
2 * (tts / Math.sqrt(2)) + tts
where I set the tts value to 15. If I change the first line to
tts = 15
The program successfully executes the equation. Where am I going wrong?
So when you get a value from gets.chomp, it defaults it to a string. What you are getting back when you enter 15 into the terminal is the string "15" instead of the integer 15. In order to fix this, you can do the following:
tts = gets.chomp.to_i
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am new to JDBC and trying following code. Could not find the error in it:
try{
Connection con = ConnectionProvider.getCon();
stmt=con.prepareStatement("insert into create_request values((select count(reqno) from create_request)+1,?,?,?,?,?)");
stmt.setString(1,obj_Leaverequest.getUser_name());
stmt.setString(2,obj_Leaverequest.getLeave_Type());
stmt.setInt(3,obj_Leaverequest.getLeave_Units());
stmt.setString(4,obj_Leaverequest.getLeave_Reason());
stmt.setString(5,"pending");
count=stmt.executeUpdate();
if(count>0){
status=true;
}
}
Update:
If I replace my code like this it works:
String sqQuery="insert into create_request values (?,?,?,?,?,?)";
stmt=con.prepareStatement(sqQuery);
stmt.setString(1,"(select count(reqno) from create_request)+1");
stmt.setString(2,obj_Leaverequest.getUser_name());
stmt.setString(3,obj_Leaverequest.getLeave_Type());
stmt.setInt(4,obj_Leaverequest.getLeave_Units());
stmt.setString(5,obj_Leaverequest.getLeave_Reason());
stmt.setString(6,"pending");
Getters are working fine, I could print their values. I guess I am wrong with the query. Please point out my mistake. Thanks in advance!!
String sqQuery="insert into create_request values (?,?,?,?,?,?)";
stmt=con.prepareStatement(sqQuery);
stmt.setString(1,"(select count(reqno) from create_request)+1");
stmt.setString(2,obj_Leaverequest.getUser_name());
stmt.setString(3,obj_Leaverequest.getLeave_Type());
stmt.setInt(4,obj_Leaverequest.getLeave_Units());
stmt.setString(5,obj_Leaverequest.getLeave_Reason());
stmt.setString(6,"pending");
Check for the "?" prepared statements index . You have 6 , but you need only 5
Hope this helps