LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2004, 07:31 AM   #1
gmarais
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Rep: Reputation: 0
php :: datetime


hi,

i have created a mysql table where i would like to store the date and time whenever a user logs into a web site. the login is done through php/mysql as well but i'm not sure what the php code is to add the current date/time into a mysql database. the field in the db is created as a 'datetime' field.

thanx
 
Old 03-05-2004, 09:55 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I just use something like this:
Code:
      $DateTime = date( "U" );

      $query = mysql_query( "insert into failed_logins ( login_id, password, ip_address, date_time ) values ( '$name', '$password', '$ClientIP', $DateTime )")
               or die ("Unable to insert into failed_logins");
You will have to format the date into a readable format when you pull it back out. The "U" get the date in the number of seconds since Jan 1970.
 
Old 03-05-2004, 09:56 PM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
The php manual has some good code examples:

http://www.php.net/manual/en/function.date.php
 
Old 03-06-2004, 04:33 PM   #4
Longinus
Member
 
Registered: Sep 2003
Distribution: Redhat 9.0 && Slackware 9.1
Posts: 420

Rep: Reputation: 30
heheh i think i know how to do this

you use a function called time()
time() just returns the current date in seconds (really long number)

do something like this when they enter your website:

$time = time();

mysql:
create table mytable(time int unsigned);

in your php code, connect to the database and insert '$time' into the field 'time'

thats it!

now all your time is gonna be like: 268729263 or something like that

so to convert the time into human readable format use the php function called

date()
http://www.php.net/manual/en/function.date.php

hope that helped
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how could i retrieve the system datetime in Linux C++? nelnel Programming 1 08-25-2005 09:09 AM
MySQL datetime jabfinger Programming 2 07-25-2005 12:27 PM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
Mysql/PHP query problem with datetime field. Pcghost Programming 2 11-11-2003 12:24 PM
html form current datetime meluser Programming 27 04-16-2003 06:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration