Hi all, I'm pretty sure this is a simple problem but i'm pretty new and my head is nothing but addled so any help at all is greatly appreciated.
I have a database with a column date. I want to manually insert dates into it using a form and then be able to SORT BY date DESC.
In my form I just have a text box where I enter dd/mm/yyyy. Will sort by work using this or do I need to put it yyyy/mm/dd. Or am I just completly missing the mark?
Inserting date
Moderator: General Moderators
Re: Inserting date
Take a look at date();, strtotime();
Then in your database use the timestamp field type.
Then in your database use the timestamp field type.
Code: Select all
$Timestamp = strtotime($Data);
$Time = date( 'Y-m-d H:i:s', $Timestamp);
// Now you can put $Time in your database because it is a formatted timestamp that MySql accepts.
-
Darragh3277
- Forum Newbie
- Posts: 12
- Joined: Tue Jun 24, 2008 9:19 am
Re: Inserting date
Thanks for the reply. I am however after changing it slighty. Now instead of a plain text box for date I have 3 boxes. A drop down menu for day & month, and also a plain text field for year (YYYY). I was wondering if it were possible to do something like this:
Code: Select all
$Timestamp = strtotime($_POST[day], $_POST[month], $_POST[year]);
$Time = date( 'Y-m-d H:i:s', $Timestamp);Re: Inserting date
Darragh3277 wrote:Thanks for the reply. I am however after changing it slighty. Now instead of a plain text box for date I have 3 boxes. A drop down menu for day & month, and also a plain text field for year (YYYY). I was wondering if it were possible to do something like this:
Code: Select all
$Timestamp = strtotime($_POST[day], $_POST[month], $_POST[year]); $Time = date( 'Y-m-d H:i:s', $Timestamp);
Code: Select all
$Merged = "{$_POST['day']}-{$_POST['month']}-{$_POST['year']}"; // One Format (of many) strtotime accepts
$Timestamp = strtotime($Merged);
$Time = date( 'Y-m-d H:i:s', $Timestamp);
// OR
$Timestamp = mktime(0,0,0,$_POST['month'],$_POST['day'],$_POST['year']);
$Time = date( 'Y-m-d H:i:s', $Timestamp);
-
Darragh3277
- Forum Newbie
- Posts: 12
- Joined: Tue Jun 24, 2008 9:19 am
Re: Inserting date
Ah you legend!! Thanks for the help! Exactly what I was looking for! Cheers!