Results 1 to 13 of 13
- 05-04-2012, 09:41 AM #1
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
how to convert as "2012-05-03" date format only
Nice To meet all
.gif)
i need a date format of "yyyy-mm-dd", only,
To get current date from the system, and store in MySQL data base.
i try with "import java.util.Calendar;"
Java Code:SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); Date today = new Date(); Date todayWithZeroTime =formatter.parse(formatter.format(today));
but it show me the format of "Fri May 04 12:57:55 IST 2012" only,
can Anyone guide me..,
Thank you for your help..,
- 05-04-2012, 09:54 AM #2
Member
- Join Date
- Sep 2011
- Posts
- 59
- Rep Power
- 0
Re: how to convert as "2012-05-03" date format only
formatter.parse() takes text and puts it back into the default date format.
formatter.format() formats the date according to its specifications.
formatter.parse(formatter.format()) will take the formatted date and convert it right back to the default format.
You don't want to parse a formatted date.
- 05-04-2012, 10:07 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: how to convert as "2012-05-03" date format only
A Date object does not have a format.
It is simply a long representing the number of milliseconds since the epoch (1/1/1970 UTC).
How is your date column represented in the database?
If it's as a DATE then there is no need to do anything other than turn the util.Date into a sql.Date.Please do not ask for code as refusal often offends.
- 05-04-2012, 10:10 AM #4
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: how to convert as "2012-05-03" date format only
Thank you for your response sir!
which one shall i fallow,
formatter.format()
or
formatter.parse(formatter.format())
replay please..,
- 05-04-2012, 10:12 AM #5
Member
- Join Date
- Sep 2011
- Posts
- 59
- Rep Power
- 0
Re: how to convert as "2012-05-03" date format only
Ahh yes. I probably didn't word my explanation very well.
format() returns a String, not a Date
As for Sql.... you can take over from here because I'm useless.
Edit:
format(date) returns your formatted date as a string
parse(formattedDate) returns a DateLast edited by brynpttrsn; 05-04-2012 at 10:15 AM.
- 05-04-2012, 10:16 AM #6
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: how to convert as "2012-05-03" date format only
ok, Thank you..,
- 05-04-2012, 10:26 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: how to convert as "2012-05-03" date format only
It might be an idea to answer my question above, because if this is going into a DATE column in MySQL there is no need to remove the time element, as setDate() will only take the date portion into the database anyway.
Please do not ask for code as refusal often offends.
- 05-04-2012, 11:17 AM #8
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: how to convert as "2012-05-03" date format only
i wants to create log in form for Client
if the Client log in with that form it will be forward to my serversocket (username, password with current time)
and i have to insert the LOG IN table with (username, password with current time and current date of server)
when log out the user i have receive the (username, password with current time)
then i update the LOG IN table with (current time) where (username and current date of server)
to avoid the repeating of same user on that same day , i wants to check with date..,
if i use the date as it is , it will never check with (where), because date will add with time stamp..,
That's all sir!..,
- 05-04-2012, 11:28 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: how to convert as "2012-05-03" date format only
You still haven't answered the question.
What MySQL datatype is the current_date column?Please do not ask for code as refusal often offends.
- 05-04-2012, 11:44 AM #10
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: how to convert as "2012-05-03" date format only
sir! The Data Type is,
The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format sir..,
- 05-04-2012, 11:55 AM #11
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Re: how to convert as "2012-05-03" date format only
I got the answer sir!
To get the current date in MySQL have to place the method of " CURDATE()"..,
i replace it in java,
I lot of Thanks to you all my Brethren's,
i am very happy now..,
- 05-04-2012, 12:02 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: how to convert as "2012-05-03" date format only
So, since it was a DATE there was no need to convert anyway.
You could simply have done:
No conversion needed at all.Java Code:java.sql.Date today = new Date(); <yourPreparedStatement>.setDate(today);
Of course, using MySQLs own built in functionality is preferable.Please do not ask for code as refusal often offends.
- 05-04-2012, 12:36 PM #13
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Similar Threads
-
Help needed for "java.io.IOException: Not in GZIP format"
By goldest in forum New To JavaReplies: 6Last Post: 08-10-2010, 09:22 AM -
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
final String currentWorld = "Java Forums"; String.format("Hello %s", currentWorld);
By mcfrog in forum IntroductionsReplies: 0Last Post: 04-02-2009, 07:02 PM -
Convert " ü " into simple " u "
By nitinb4u in forum New To JavaReplies: 4Last Post: 02-23-2009, 08:35 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks