Monday, June 17, 2013

Converting date in PostgreSQL

Get current date, month, and year (return type is DOUBLE PRECISION) :
                     
select EXTRACT(DAY FROM now());

select EXTRACT(MONTH FROM now());

select EXTRACT(YEAR FROM now());


Get current date, month, and year (return type is TEXT) :
select to_char(now(), 'YYYY'); -- year (4 and more digits)

select to_char(now(), 'MM');  -- month number (01-12) with leading zero

select to_char(now(), 'DD');  -- day of month (01-31) with leading zero


For complete complete documentation : to_char

Create a loading image in Java desktop application

This code are equals with
Application.ProcessMessages
in Delphi or
Application.DoEvents
in VB

                     lblLoading.setVisible(true);  
                     new Thread(new Runnable() {  
                          private boolean done = false;  
                          @Override  
                          public void run() {  
                               // time consuming algorithm.  

                               done = true;  
                               if (done) {  
                                    SwingUtilities.invokeLater(new Runnable() {  
                                         @Override  
                                         public void run() {  
                                              lblLoading.setVisible(false);  
                                         }  
                                    });  
                               }  
                          }  
                     }).start();