Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to convert '2005-9-22 3:9:00' to 200509220309

Status
Not open for further replies.

andrewxie

Programmer
May 29, 2003
15
US
i use
SELECT concat(YEAR(now(), MONTH(now()), DAY(now()), HOUR(now()), MINUTE(now()));

return 200592239. but i want double digit hour and minute

anybody knows.
 
i wouldn't use date_format() for this, i'd use date arithmetic:

[tt]select floor(now()/100) as date_number[/tt]

:)

r937.com | rudy.ca
 
just to be more diverse.

select substring(NOW() + 0,1,12);


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
thanks both of you. they all works. have a nice day!
 
by the way, anybody know built-in function in perl to convert localtime() to '200509230809' except the following function.

sub convertDate
{
my ($varDate) = @_;
if (day$(varDate) < 10)
{
dd = "0"day($varDate);
}
else
{
dd = day($varDate);
}
if (month($varDate) < 10))
{
$mm = "0".month($varDate);
}
else
{
$mm = month($varDate);
}
$convertDate = year(varDate)$mm$dd;
}
 
How about:
[tt]
@lt=localtime(time);
sprintf
(
$datestring,"%d%02d%02d%02d%02d",
$lt[5]+1900,$lt[4]+1,$lt[3],$lt[2],$lt[1]
);
[/tt]
 
Sorry, I'm getting my C and Perl mixed-up. That should of course have been:
[tt]
@lt=localtime(time);
$datestring=
sprintf
(
"%d%02d%02d%02d%02d",
$lt[5]+1900,$lt[4]+1,$lt[3],$lt[2],$lt[1]
);
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top