Date Insertion
Moderator: General Moderators
-
CoolAsCarlito
- Forum Contributor
- Posts: 192
- Joined: Sat May 31, 2008 3:27 pm
- Contact:
Date Insertion
Is there a way when you have a php script that when you fill out a little web form to create a member and have it sent to a database it'll also take the date of when the user was created and store that date in the database as well?
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Date Insertion
If you're using DATETIME field in the database you can use MySql function NOW() directly in your query or PHP date() function to format the date appropriately. if you save time in DB as a timestamp, you can use php time(). Just make sure your PHP timezone and MySql timezone settings are in sync.
-
CoolAsCarlito
- Forum Contributor
- Posts: 192
- Joined: Sat May 31, 2008 3:27 pm
- Contact:
Re: Date Insertion
Okay I'm lost. I tried to follow but just to make sure you understand what I'm wanting. I'm sure you know what I'm going to say but I'm going to describe it again. What I mean is when the new record is created it also posts the date it was created and inserted into the row called "date created".
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Date Insertion
Like I said if your date_created field is, for example, DATETIME type you can use
Code: Select all
$sql = "INSERT INTO products
(name, description, date_created)
VALUES
('{$name}', '{$description}', NOW())";
// or
$date_created = date('Y-m-d H:i:s');
$sql = "INSERT INTO products
(name, description, date_created)
VALUES
('{$name}', '{$description}', '{$date_created}')";
-
CoolAsCarlito
- Forum Contributor
- Posts: 192
- Joined: Sat May 31, 2008 3:27 pm
- Contact:
Re: Date Insertion
Ahh thank you
-
CoolAsCarlito
- Forum Contributor
- Posts: 192
- Joined: Sat May 31, 2008 3:27 pm
- Contact:
Re: Date Insertion
Okay so I'm trying to put the date as (month day, year)
And I put this as the syntax:
$query = "SELECT * FROM titlehistory FORMAT datecreated ('m-d-Y')";
Could not retrieve the data because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datecreated (m-d-Y)' at line 1. The query was $query.
Can you tell me why it's bringing that error?
And I put this as the syntax:
$query = "SELECT * FROM titlehistory FORMAT datecreated ('m-d-Y')";
Could not retrieve the data because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datecreated (m-d-Y)' at line 1. The query was $query.
Can you tell me why it's bringing that error?
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Date Insertion
Take a look at the MySql DATE_FORMAT() function.
-
CoolAsCarlito
- Forum Contributor
- Posts: 192
- Joined: Sat May 31, 2008 3:27 pm
- Contact:
Re: Date Insertion
//Define the query
$query = "SELECT * FROM titlehistory FORMAT datecreated (%m %e,%Y)";
Still gives me the same result.
$query = "SELECT * FROM titlehistory FORMAT datecreated (%m %e,%Y)";
Still gives me the same result.
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Date Insertion
When i said "Take a look", I meant READ. The link I gave you has several examples of DATE_FORMAT() function use.