Welcome Guest, Not a member yet? Register   Sign In
mysql format date value. converting from form submit?
#1

[eluser]artlover[/eluser]
Hi Friends,

my question is about date format :/

Code:
$datestring = "%d.%m.%Y %h:%i";
$time = time();
$data['localtime'] = mdate($datestring, $time);

echo $localtime;

this codes gives me 16.07.2009 01:53 thats very good. i display this at form for news like info. user fill the form and submit. now i need to get this date in a good format for db :/ which is 2009-07-08 06:07:06

how can I convert the date value from form to db compatible? :/

thanks a lot for helps!
#2

[eluser]Đaяк Đaηтє[/eluser]
Code:
<?php
$date = "16.07.2009 01:53";
$aux1 = explode(" ",$date);

$aux2 = explode(".",$aux1[0]);

$date = $aux2[2]."-".$aux2[1]."-".$aux2[0]." ".$aux1[1];

echo $date;
?>
#3

[eluser]darkhouse[/eluser]
Why not just do

Code:
$date = date('Y-m-d H:i:s');
#4

[eluser]Đaяк Đaηтє[/eluser]
Maybe you're right, if he only needs to save the current date everytime, but if he needs to work with the stored dates, to show it and save it then, date('Y-m-d H:iConfused') is not enough. But both answers are perfectly valids
#5

[eluser]darkhouse[/eluser]
[quote author="SAC Version 27.11" date="1247823935"]Maybe you're right, if he only needs to save the current date everytime, but if he needs to work with the stored dates, to show it and save it then, date('Y-m-d H:iConfused') is not enough. But both answers are perfectly valids[/quote]

Looking at his code, that's what he's doing, since he's got $time = time(); But if he needs it based on another time, then another method might be this:

Code:
$date = date('Y-m-d H:i:s', strtotime($localtime));

I haven't tested it though.
#6

[eluser]Đaяк Đaηтє[/eluser]
You're right darkhouse, this can help me too. By the way, you're example works fine.

Thanks for your reply.




Theme © iAndrew 2016 - Forum software by © MyBB