Welcome Guest, Not a member yet? Register   Sign In
storing the date of a blog post to db
#1

[eluser]rabidmacine9[/eluser]
hello there!
I have a bd called "myBlog" and it contains a table called "entries" inside "entries" there is a column named "date"
can somebody tell me a way to store the current date the moment I make a post?
thanks
#2

[eluser]danmontgomery[/eluser]
CodeIgniter's now() function, or MySQL's function of the same name
#3

[eluser]Ivar89[/eluser]
Code:
<?php
$this->load->helper('date');
$datestring = "%Y-%m-%d";
date_default_timezone_set('Europe/Paris');
?>
that the current date then echo it in an hidden input field and when you done just insert in db:o
Code:
<input type="hidden" class="date" name="datPublicationDate" value="<?php echo mdate($datestring);?>">

EDIT: noctrum is WAY more valid thoughTongue. This is if you don't know how to do it any other wayTongue
#4

[eluser]n0xie[/eluser]
Just use a timestamp and let the DB take care of it:
Code:
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
#5

[eluser]rabidmacine9[/eluser]
how would I use timestamp?
I mean I created a colummn of timestamp type but how would I input the date-time to it?
#6

[eluser]Ivar89[/eluser]
By using the query he posted
and check the link, maybe that makes more sense ^^
#7

[eluser]mddd[/eluser]
I agree with noxie.
You can configure the table to automatically insert the current timestamp into the field when it is created. That way you don't have to do anything. Just don't specify the field at all. It will automatically be filled.
#8

[eluser]n0xie[/eluser]
[quote author="rabidmacine9" date="1276112984"]how would I use timestamp?
I mean I created a colummn of timestamp type but how would I input the date-time to it?[/quote]

Replace 'tablename' and 'columnname' to whatever is appropriate for you.

Code:
ALTER TABLE tablename   add column `columnname` timestamp NOT NULL default CURRENT_TIMESTAMP on
update CURRENT_TIMESTAMP;

Then it will automatically insert the correct timestamp whenever you create or update a new 'entry'.
#9

[eluser]rabidmacine9[/eluser]
thanks for the replies...
actually I'm totally new to this
I just followed the video tutorial "make a blog in 20 minutes" and I'm trying to add some features...
so I created a date_time field on my table and I gave it timestamp type...
it still doesn't work though...
I'm pretty sure that this is happening because I use the scaffolding feature in order to update my entries...
any ideas on how I can solve this?




Theme © iAndrew 2016 - Forum software by © MyBB