I have to compare an EQUAL comparison between dates from UI and DB. Its working with below code
ExtJs Code :-
xtype: 'datefield'
,fieldLabel:'By Date'
,name: 'byDate'
,format: 'd-m-Y'
,flex:1
and Code in Java is :-
query.addCriteria(Criteria.where("bookingtime").regex(byDate, "i"));
The format d-m-Y gives me date in format 27-11-2016 or 15-10-2016. If the date in DB is as same as in date from UI ,like 27-11-2016 etc, this works like a charm.
But the problems arises when I select date in UI as 07-01-2016 which becomes 7-1-2016 in java. Since date in DB is in format 07-01-2016 and it fails the match and I get nothing.
Could you please help.
Related
I have a column "created_date" in my table in SQL server. It is currently in format "dd-mm-yy hh:mm:ss" and I want to change it to "yyyy:MM:dd hh:mm:ss" using Java code.
Simple date format is throwing error. Is there any other way to do it?
I am using Spring-Boot for managing my Rest-API. I am storing a Date of birth in my postgreSQL DB as 02/10/1983 using the API with a json payload as "dateOfBirth": "02/10/1983", and Its stored as it is, and the DB result is showing the exact date.
When I am fetching the record using Spring-Boot API call, the date is returned one day prior as 01/10/1983. Every date value is returned a day prior.
I also added a date to insert date using the below code:
long millis=System.currentTimeMillis();
Date currentDate=new Date(millis);
This also saves the date as current date in the DB but returning One day prior the date using rest API get calls.
I'm struggling with selecting a date range from jquery datepicker date range selector using selenium web driver.
Following image shows the date picker.
I need to select a date range from this calendar. I've tried following links.
Link 1
Link 2
Only thing i found relevant is the following code segment.
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#class='demo-frame'][#src='/resources/demos/datepicker/default.html']")));
driver.findElement(By.id("datepicker")).click();
System.out.println("Datepicker Clicked");
But, it doesn't show how to select a date range from the date picker.
Thanks in advance. :-)
From my experience, it makes no sense to interact with such components via findElement calls. Unless you want to make your tests unstable. Such datepickers usually have public API, which could be accessed directly via JavascriptExecutor. Quick sample:
$( ".selector" ).datepicker( "setDate", "10/12/2012" );
could be used the following way:
executeScript("$( '.selector' ).datepicker( 'setDate', '10/12/2012' );");
So I'd recommend you to find out which JS library is used to render your datepicker, check their API, and access it directly the way I've written above.
Give a try to below code and lets see if it works.
I stole the code from select the Date Picker
((JavascriptExecutor)driver).executeScript ("document.getElementById('elementid').removeAttribute('readonly',0);"); // Enables the from date box
WebElement dateBox= driver.findElement(By.id("elementid"));
dateBox.clear();
dateBox.sendKeys("8-Dec-2014"); //Enter date in required format
I am using Orientdb with Eclipse and the orientdb-client jar. I use the following statement to read out Messages:
List<ODocument> result = connection.command(
new OSQLSynchQuery<ODocument>(
"SELECT * FROM Message"))
.execute();
At first glance the results looks right, but then i realized that the time i read out from a DATTIME field is wrong.
When i run the query "select * from Message ", the locahost version gives me the following results (just a part of it):
When i run the java snippet from above, the results looks like :
For the formating i use a SimpleDateFormat:
DateFormat formatter = new SimpleDateFormat("HH:mm:ss a");
String time = formatter.format(each.field("Time"));
So why is the hour of the date different ( 2 hours) ? Could it be a Timezone issue?
It because database returns results in database's timezone.
You can see it from studio in section Db->configuration.
Command to update timezone looks like
alter database timezone GMT+6
i have table "news", that has a column called dateNews (type date )
in PostgreSQL the date has the following format : 2014-04-16
but in my jpa web service the format is the following : "2014-04-16T00:00:00+03:00"
how can i format my date to the following format : dd/mm/yyyy
and where should i do it is it in my PostgreSQL database or in my jpa web service ?
This conversion should be done in the service, not at the database level. Make sure your field is type java.sql.Date and use java.text.SimpleDateFormat.
see http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
Main reasons to add this at the service level are extensibility and maintainability. You want a single point where you do all this formatting, probably based on user preferences. You don't want to add this to every query you are doing, and maintaining the format throughout those queries.
Use to_char() to output a formated string (text):
SELECT to_char(datenews, 'dd/mm/yyyy') FROM news;