select date in desired format

Ads
 

select date in desired format

how to select date from the database in DD/MM/YYYY format, because if i am trying select data from the database i am getting value in yyyy/mm/dd and time format like below "2012-05-07 00:00:00.0"

View Answers

May 2, 2012 at 1:03 PM

import java.sql.*;
import java.util.*;
import java.text.*;

public class RetrieveDate {
public static void main(String args[]) {
ResultSet rs = null;
Connection con = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
stmt = con.createStatement();
rs = stmt.executeQuery("select dob from data");
while (rs.next()) {

java.sql.Timestamp ts = rs.getTimestamp("dob");
java.sql.Date  date      = new java.sql.Date(ts.getTime());  
java.util.Date dd = new java.util.Date(date.getTime());
SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");
System.out.println(sdf.format(dd));
}
} catch (Exception e) {
e.printStackTrace();
} 
}
}

Here field dob is of datetime type.

Ads









Related Tutorials/Questions & Answers:
select date in desired format
select date in desired format  how to select date from the database in DD/MM/YYYY format, because if i am trying select data from the database i am getting value in yyyy/mm/dd and time format like below "2012-05-07 00:00:00.0
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP
Advertisements
Mysql Date Format
for showing Year, numeric, four digits Query:- SELECT DATE_FORMAT('2008-12-15... Mysql Date Format       Mysql Date Format explains you the way of formatting Date
Select today's date sql
Select today's date sql   I wanted to show the data from database according to the current date. So, can anyone give me the select today's date sql query? Thanks!   select current date in mysql query select * from
String to date with no format
into a date .. this is simple .. but i want to do it without knowing the date format... date format can be (mm-dd-yyyy) if the 99th record also was 06-06-2006 the result should be date format can be (mm-dd-yyyy;dd-mm-yyyy) can sum1 please help me
Date auto format
Date auto format  Hi, I have jsp page and Date field with input type. Requirement is, if we enter date as MMDDYY or MMDDYYYY and clicking the tab the date(MMDDYY or MMDDYYYY) have to auto format to MM/DD/YYYY. could you please
String to Date format
String to Date format  My Date format is String Eg(Jan 20 2011 ).... How to Change This values Like to database date format Eg(2011-01-20) using..."; Date date=new Date(d); SimpleDateFormat sdf=new
java format date
java format date  Hi, How can I format the date in the following...) { Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); String formattedDate=sdf.format(date
Hibernate Date Format
This section contains description of Hibernate Date Format
NSDateformatter format Date
NSDateformatter format Date  Hi, What is the correct way of writing NSDateFormatter in string format. Thanks.   For current Date in NSDate... that represent other data types. For example to show the date in string format we'll
date format in javascript
date format in javascript  display date format as dd/mm/yyyy and day... help me. thank u var date=/^\d{2}\/\d{2}\/\d{4}$/ if(document.userform.joindate.value.search(date)==-1) { alert("please enter date format as dd/mm/yyyy
Mysql Date Format codes
in dd-mm-yy. mysql> select date_format(now(),'%e-%m-%y')as Date...; mysql> select date_format(now(),'%w')as DayofWeek; Output... format(now(),'%e') return you the day of the month. mysql> select date
Sql Date and Time Format
. SELECT DATE_FORMAT('2008-12-15 15:53:00','%W %e %M %Y %r'); Output... Sql Date and Time Format     ...; is used to  format date and time.  SYNTAX:- DATE_FORMAT(date,format
Mysql Date Format
Mysql Date Format      .... The Tutorial helps you to write the Date Format in SQL Query.  date_format... and year.  Query for formatting currentdate:- mysql> select date
Java Date Format Example
Java Date Format Example You can format date in many ways. In this tutorial Format class is used to format the java date in to the different formats... in the following ways. 1. Create an object of Format class. 2. Set The required date
Date not getting in proper format
Date not getting in proper format  import java.util.*; class Date { public static void main(String[]args) { Date d = new Date(100000000000L); System.out.print("1st date"+d.toString()); } } out put:- 1st date@3e25
Date Format required to change in java
Date Format required to change in java  can we change the format of date like sql as per our requirements???If yes then please give the detail solution
date format updated
date format updated  package LvFrm; import java.awt.Color; import... panel1,panel2,panel3,panel4; Font f1; JComboBox i1,j1,k1; JButton b1,b2; //for date...); panel2.setBorder(b2); frm.add(panel2); /*for date entry & adding
struts2.2.1 date Format example
struts2.2.1 date Format example. In this example, We will discuss about the different type of date format using struts2.2.1. Directory structure of example... Format Example</title> </head> <body> <h2>Date
Mysql Date Format Convert
Mysql Date Format Convert     ... and time. Now, we help you to convert the Mysql Date Format Conversion into other... 'Mysql Date Format Convert'. To grasp this concept we use Date now ( ) Query
Simple Date Format Example
Following is a simple date format example made using Format class. We have uses a pattern of special characters to date and time format. In this example, SimpleDateFormat:class is used to format date into text and parse text into date
How to convert current date to dd mm yyyy format in Java?
to achieve the conversion of current date into this desired format? Thanks  ... the current date into desired format */ public class CurrentDateToString...How to convert current date to dd mm yyyy format in Java?  Hi, How
validationrule for date as format yyyy-mm-dd in drools
validationrule for date as format yyyy-mm-dd in drools  Please give idea about this one..I have two textfield. User can select the date from... format yyyy-mm-dd: How i write the validation rule for date as a format yyyy-mm-dd
Mysql Date Select
Mysql Date Select       The Tutorial elaborate an example from 'Mysql Date Select'. This section makes.... The SELECT DATE ('YYYY-MM-DD') is used to return the current selected date. SELECT DATE
ModuleNotFoundError: No module named 'date-format-machine'
ModuleNotFoundError: No module named 'date-format-machine'  Hi, My... named 'date-format-machine' How to remove the ModuleNotFoundError: No module named 'date-format-machine' error? Thanks   Hi
ModuleNotFoundError: No module named 'date-format-machine'
ModuleNotFoundError: No module named 'date-format-machine'  Hi, My... named 'date-format-machine' How to remove the ModuleNotFoundError: No module named 'date-format-machine' error? Thanks   Hi
date format to be updated with current date time
date format to be updated with current date time  package LvFrm...; JButton b1,b2; //for date month year entry String strD[]={"Day","1...); /*for date entry & adding date into panel 2 also addind panel
How to convert current date to mm dd yyyy format in Java?
How to convert current date to mm dd yyyy format in Java?  Hi, How to convert current date to mm dd yyyy format in Java? Share me the program... for converting current date into MM-dd-yyyy format. Here is full code: package
Mysql Date Parse
to select using parsing the date. mysql> SELECT DATE_FORMAT...; Mysql Date is used to parse the string date time in Date Format function and retrieve the date in specified format. Understand with Example The Tutorial
How to convert date to UTC format in Java?
How to convert date to UTC format in Java?  Hi, What is UTC Date format and How to convert date to UTC format in Java? I need simple to learn... representation and the String UTC to the date format. Thanks   Hi, Here
Simple Date Format Exception
Simple Date Format Exception       Simple Date Format Exception inherits from a package name... and normalization of date. Simple Date-format provides you to work on choosing any

Ads