Welcome Guest, Not a member yet? Register   Sign In
how to insert a date into the database?
#1

[eluser]Unknown[/eluser]
i want to insert time and date along with post details ? how insert date and time in my database
#2

[eluser]NateL[/eluser]
First, You posted in the job board. Post in the right section next time ;-)

Onto your question...
You could use the date() function:

Code:
<?php
echo date('m-d-Y');  // outputs 09-19-2009
?>

so on your insert statement, it would look something like this:

Code:
$date = date('m-d-Y');
$this->db->insert('mytable', $date);


If you want more control, down to the second, you could use Epoch time. Look on the php.net manual for the time() function.
#3

[eluser]jedd[/eluser]
Stick with ISO 8601 for your date formats - apart from being implicitly sensible, it aligns (more closely) with MySQL's native format.

You may be better off generating your datestamps from within your database directly, using the NOW() function (in MySQL - there's probably comparable functions for other RDBMS's).

Mind, if you're asking this question, then you probably don't want to track timezones for different users, etc, so it's probably less important for you to have accurate date information.
#4

[eluser]ray73864[/eluser]
I like to store date/times as an integer, and stick the seconds into that field, allows you to do anything you like when you pull it out then, display it however you like, change it around to and all.
#5

[eluser]jedd[/eluser]
That's going to be nice and fast if you're just doing comparisons between two dates, but I think you get some measurable performance benefits once you start using the native date and time types - for example selecting a bunch of records from a given month. Sure, you can work out your boundaries for each month, but then you end up with a bunch of new functions, and a bit of overhead.

There are CI/php functions to convert 8601 / MySQL date formats back into unix time (number of seconds since 19700101T0000UTC Wink




Theme © iAndrew 2016 - Forum software by © MyBB