Friday, 29 May 2015

Tips and tricks- 4

1. Query to find week day in PostgreSQL

select to_char(current_date,'Day');
Friday


2. Query to find current day of week

select to_char(current_date,'D');
6

3. Query to extract year and month from date in PostgreSQL

SELECT
 EXTRACT(YEAR FROM to_timestamp(column_name, 'YYYY-MM-DD')) years,
 EXTRACT(MONTH FROM to_timestamp(column_name, 'YYYY-MM-DD')) months
 FROM table_name

4. Query to find number of days between two dates in PostgreSQL

select '2015-05-22'::date - '2015-05-12'::date
10

5. Query to display name of month in PostgreSQL

SELECT to_char(to_timestamp (4::text, 'MM'), 'TMmon')
Apr

6. How to get fully qualified path name for a file in /src/Resources folder in Eclipse Java Project

className.getClass().getResource("/Resources")

7. List all filenames in a particular directory using java

public List<String> listFiles(String location){
List<String> fileNames = new ArrayList<String>();
File[] files = new File(location).listFiles();
for (File file : files) {
   if (file.isFile()) {
       fileNames.add(file.getName());
   }
}
return fileNames;
}

8. Find Elements in list1 but not in list2 in java

ListUtils.subtract(list1,list2);

9. Find union of two lists in java

ListUtils.union(list1,list2);

Mistakes lead us to right choice!!

No comments:

Post a Comment