www.webdeveloper.com
Results 1 to 3 of 3

Thread: Format Date

  1. #1
    Join Date
    Jul 2007
    Posts
    183

    Format Date

    Hi Guys

    I wasn't sure where to post this but I have the following query:

    Code:
    ResultSet rs = DB.exQuery("SELECT max(transaction_date) as 'date', transaction_value, transaction_type FROM transaction_log WHERE user_id = " + user.getId());
    I am using TIMESTAMP as the default method of saving the date/time to the DB. I want to custom format the date but don't know how to. I tried DATE_FORMAT but since am already using MAX I don't know how I can implement to two.

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Nest the MAX inside the DATE_FORMAT

    DATE_FORMAT(max(transaction_date),'%Y-%m-%d') as 'date'

  3. #3
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    since i now know you're using java, why not just do the standard JDBC thing to do? then use simpledateformat to format it how you want.

    Code:
    ResultSet rs = DB.exQuery("SELECT max(transaction_date) as 'date', transaction_value, transaction_type FROM transaction_log WHERE user_id = " + user.getId());
    if(rs.next()) {
    java.util.Date d = rs.getDate("date");
    SimpleDateFormat sdf = new SimpleDateFormat("the format you want");
    String value = sdf.format(d);
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles