Dateformat problem |
[eluser]Zimooon[/eluser]
Hey guys, Im struggeling with a simple task.. I got an input form field for the date. In my MYSQL database my date type is DATE and the format YYYY/MM/DD . But in my input i use DD.MM.YYYY and this is the format i want to display too. Now everytime i write in my input f.e. 02.02.2011 it gives me in this case 2002-02-20 ... Don't know how to fix it. In MYSQL ? or where? best regards
[eluser]danmontgomery[/eluser]
You have to format it to store it, then format it again to display it. http://php.net/manual/en/function.date.php Code: $date = date('Y-m-d', strtotime($this->input->post('date'));
[eluser]Zimooon[/eluser]
Ok so in my MYSQL DB i got TIMESTAMP . How do i change it to store it? I would display it with UNIX_to_human? best regards
[eluser]cahva[/eluser]
TIMESTAMP format is almost the same as DATETIME (YYYY-MM-DD etc.). noctrum gave you the tip how to translate the date to date format that mysql uses. When you output the date, use the same date function: Code: echo 'The date is: '.date('d.m.Y',strtotime($row->date_field));
[eluser]Zimooon[/eluser]
Allright i think i got it now Next prob is : I want to compare now() with my current date so i want to save my date as a integer. f.e. now() = 1304003142 . But when i enter in my date(int(20) ) 2020-10-10 11:11:11 it only writes 2020 to my database . I heard about sth called explode to get rid of - and : but it won't work(maybe i just set it wrong but all the trys weren't succesful. Integer is the best format to compare , isn't it? best regards
[eluser]Zimooon[/eluser]
Oh it works now big thanks to you too guys have a nice .. hmm whatever day night morning evening , wherever you from
[eluser]cahva[/eluser]
Why you want to save the date as integer(as unix timestamp I presume)? NOW() returns date and time with the same format. You can compare dates perfectly fine so theres no need to turn them into unix timestamps: Code: SELECT NOW() > '2011-04-28 00:00:00'; I recommend you read the Mysql manual about Date and Time functions. |
Welcome Guest, Not a member yet? Register Sign In |