I want to write a validation in such a way that my query should result true if same CCN and date already exist in DB, from JSON and IN DB datetime is saved in "yyyy-MM-dd HH:mm:ss", but in my validation i need to take only date[yyyy-MM-dd] and compare.
I am new to spring boot
This is what i have in my model class
#JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
#Temporal(TemporalType.DATE)
private Date datetime;
Repository for my class
#Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM TABLEX c WHERE c.ccn = :ccn and c.datetime= :datetime")
boolean isExistbyCcnAndDate(#Param("ccn") String conveyancereferencenumber, #Param("datetime") #DateTimeFormat(pattern = "yyyy-MM-dd") Date date);
When i try this it gives result as always false.
This is how i am passing values to repository
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateString = sdf.format(model.getDatetime());
convertedDate = sdf.parse(dateString);
isExistCcnAndDate=repository.isExistbyCcnAndDate(model.getCcn(),convertedDate);
Check out my sqlfiddle.
http://sqlfiddle.com/#!9/5305eb/3
Using sql fiddle this will work:
Create shema:
create table c(datetime DATETIME, ccn TEXT)
insert into c (datetime, ccn) values ('2020-01-01 10:10:50' , 'a');
Try to read and filter step by step:
select * from c;
select * from c where c.datetime = '2020-01-01 10:10:50';
select * from c where date(c.datetime)= date('2020-01-01');
As I already said, whether you can use date(), DATE() or whatever depends on your server, sqlfiddle is MySQL.
Related
I don't have idea how to split data using a query... I want to implement the split on the WhERE Clause because I am trying to select data Where the value of WHERE Clause is separated with comma
My sample Query
SELECT Name FROM Entry_time WHERE Edate = '"Combobox.selectedItem"'
I want that only the date
The Data value from database:
Fri, 02/21/15
First, convert to a DateTime, then to a formatted string expression for Access SQL:
Dim FilterDate As DateTime
Dim FilterText As String
Dim Provider As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
FilterDate = DateTime.ParseExact(Combobox.selectedItem.Text.Split(",")(1).Trim(), "MM'/'dd'/'yy", Provider)
FilterText = FilterDate.ToString("yyyy'/'MM'/'dd")
SQL = "SELECT [Name] FROM Entry_time WHERE Edate = #" + FilterText + "#"
I want to put this format data on my table: 2018-12-04T13:05:00-00:00
This should be done with a query:
$uPqr = $conn->query("UPDATE table SET dateModified = "the date goes here" WHERE id = 25");
I don't want to write the date on the query, i want to know if there's a function like NOW() or time() that do it automatically.
If you want the current time -- on the server -- then just use now():
$uPqr = $conn->query("UPDATE table SET dateModified = now() WHERE id = 25");
I have to update table which have column data type as integer, but I have an input as a datetime. this is query that i hve writen
UPDATE T_SCH_ETAX_TEMP SET CURRTIME = UNIX_TIMESTAMP
(TIMEDIFF("(SELECT DATE_FORMAT(?,'%H:%i:%s') TIMEONLY)", "(SELECT
DATE_FORMAT(CURRENT_TIMESTAMP,'%H:%i:%s') TIMEONLY)"), LENGTHTIME =
UNIX_TIMESTAMP(TIMEDIFF("(SELECT DATE_FORMAT(?,'%H:%i:%s')
TIMEONLY)", "(SELECT DATE_FORMAT(CURRENT_TIMESTAMP,'%H:%i:%s')
TIMEONLY)")
any one can help how to convert timestamp result as an integer so I can update the table using SSIS
I could be wrong, please forgive me if I am, but you seem to want something simpler:
UPDATE T_SCH_ETAX_TEMP
SET CURRTIME = UNIX_TIMESTAMP(
TIMEDIFF(TIME(?),
TIME(CURRENT_TIMESTAMP))),
LENGTHTIME = UNIX_TIMESTAMP(
TIMEDIFF(TIME(?), TIME(CURRENT_TIMESTAMP)));
Which would only require 2 parameters ('ss');
If this is the case, in can be simplified to:
UPDATE T_SCH_ETAX_TEMP
SET CURRTIME = UNIX_TIMESTAMP(
TIMEDIFF(?,
CURRENT_TIMESTAMP)),
LENGTHTIME = UNIX_TIMESTAMP(
TIMEDIFF(?, CURRENT_TIMESTAMP));
if you pre-format your parameter strings
Okay here is the scenario, I need to insert a specific date in mysql. Everytime I insert this date I get 0000-00-00.
Everytime a user pays between the 1st and the 20th of the month then the wb_due-date column would increment the month by 1
Ex.
I have a default value of wb_paid-date = 2013-10-15 and wb_due-date = 2013-10-20.
Now User1 Paid on 2013-10-15 and after I clicked button, the date saved on wb_due-date was 0000-00-00 instead of 2013-11-20
Take a look at my code
Function iterate(ByVal d As Date) As String
Dim m As Integer = d.Month
If d.Month >= 1 And d.Month <= 11 Then
m += 1
ElseIf d.Month = 12 Then
m = 1
End If
Return m
End Function
cmd = New MySqlCommand("INSERT INTO tbl_billing(wb_paid-date, wb_due-date)
VALUES(CURDATE(), iterate(Now.Date) , con)
First, let's fix your function:
Function iterate(ByVal d As DateTime) As String
Return d.AddMonths(1).ToString("yyyy-MM-dd")
End Function
Also, if you're putting a string date into command, you're almost certainly doing something wrong. Let's just do this:
Function iterate(ByVal d As DateTime) As DateTime
Return d.AddMonths(1)
End Function
Then we'll fix your Sql Command:
cmd = New MySqlCommand("INSERT INTO tbl_billing(wb_paid-date, wb_due-date) VALUES(CURDATE(), ? " , con)
cmd.Parameters.Add("?", SqlDbType.DateTime).Value = iterate(Today)
How do i write a Linq to SQL query that translates into the following:
SELECT CAST(DATETEXT AS datetime) FROM mytable
var dates = from row in mytable
select DateTime.Parse(row.DATETEXT);
There are method overloads for DateTime.Parse that allow you to specify a format.
actually, you won't be needing that. just parse it as datatime when you will use the field value. here is an exaple;
var query = from c in mytable
select c;
then when you will use it;
DateTime _value = (DateTime)query.SingleOrDefault().DATETEXT
but if you wanna use it so much. here is an example;
NorthwindEntities _e = new NorthwindEntities();
public void poo() {
var query = from e in _e.Products
select DateTime.Parse(e.DateText);
}