For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2004 > Inserting Current Date into MySQL Database









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Inserting Current Date into MySQL Database
Gerard Shea

2004-08-20, 4:33 am

OK, I am a complete Newbie at this, well... almost...

I am creating a database that accepts members. I need to know how to insert
the date of joining into the database, using a PHP script. Obviously this
has to be done without using an input field.

I can't provide specific code because it is a general principle I am after
so I can utilise it in a number of scripts.


Fat Bloke

2004-08-20, 4:33 am

On Fri, 20 Aug 2004 07:02:29 GMT, "Gerard Shea" <gpshea@tsn.cc> wrote:

>OK, I am a complete Newbie at this, well... almost...
>
>I am creating a database that accepts members. I need to know how to insert
>the date of joining into the database, using a PHP script. Obviously this
>has to be done without using an input field.
>
>I can't provide specific code because it is a general principle I am after
>so I can utilise it in a number of scripts.
>

I have a column in each table

FIELD date_added TYPE date

then, in the php code -

$Query="INSERT INTO $TableName ( field1, field2.... date_added ) VALUES
('$field1', '$field2', ... curdate() )";

Clearly, this does not need an input field in your forms.

HTH.
------------------------------------------------------------

This post did not necessarily reflect my opinions. So there.

Sent from within Forte's Agent.

Pull the pins out to reply direct.
Gerard Shea

2004-08-20, 4:33 am

I just wish to clarify that I am using an "Insert Record" server behaviour -
if that makes any difference...

"Gerard Shea" <gpshea@tsn.cc> wrote in message news:4125a14d$1@grungy...
> OK, I am a complete Newbie at this, well... almost...
>
> I am creating a database that accepts members. I need to know how to

insert
> the date of joining into the database, using a PHP script. Obviously this
> has to be done without using an input field.
>
> I can't provide specific code because it is a general principle I am after
> so I can utilise it in a number of scripts.
>
>



Charles Pelkey

2004-08-22, 8:56 pm

To get the current date via SQL, use this:

NOW()

as in :
INSERT INTO tablename (field1,field2,date_field)
VALUES('field1_value','field2_value',NOW
());


"Fat Bloke" <fatblokeonbikepins@pinsjohnstone-wheelers.co.uk> wrote in
message news:859bi0d9bkd3loaggplhqvubv5nvglgrc3@
4ax.com...
> On Fri, 20 Aug 2004 07:02:29 GMT, "Gerard Shea" <gpshea@tsn.cc> wrote:
>
insert[color=darkred]
this[color=darkred]
after[color=darkred]
> I have a column in each table
>
> FIELD date_added TYPE date
>
> then, in the php code -
>
> $Query="INSERT INTO $TableName ( field1, field2.... date_added ) VALUES
> ('$field1', '$field2', ... curdate() )";
>
> Clearly, this does not need an input field in your forms.
>
> HTH.
> ------------------------------------------------------------
>
> This post did not necessarily reflect my opinions. So there.
>
> Sent from within Forte's Agent.
>
> Pull the pins out to reply direct.



Centurion

2004-08-22, 8:56 pm

Gerard Shea wrote:

> OK, I am a complete Newbie at this, well... almost...
>
> I am creating a database that accepts members. I need to know how to
> insert
> the date of joining into the database, using a PHP script. Obviously this
> has to be done without using an input field.
>
> I can't provide specific code because it is a general principle I am after
> so I can utilise it in a number of scripts.


For user who join NOW, ie, real-time.
1. Grab the current system time (ie, system clock on the we server)
2. Format #1 appropriately for the database
3. SQL insert statement.

For loading up historical data.
1. Load join dates from a source (other database, file, etc)
2. Format #1....etc
3. SQL insert.

Which bit are you stuck on? If you need to take into account time zones,
then the client's browser may provide some useful hints.

Cheers

James
--
"Life is too important to take seriously."
-- Corky Siegel

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com