473,378 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

timestamp

In mysql, I have a field defined as a time stamp. It is storing value
as 0000-00-00 00:00:00. It to store it in seconds.

<?PHP
$entered = mktime();
echo "<INPUT TYPE='text' NAME='$entered' VALUE='$entered' SIZE='13'
READONLY>";
?>

What am i doing wrong?
Jun 2 '08 #1
7 1879
The TIMESTAMP data type has varying properties, depending on the MySQL
version and the SQL mode the server is running in. You should read the
following to understand it better. http://dev.mysql.com/doc/refman/5.0/en/datetime.html

OR

You can store $entered as LONGINTEGER, since mktime returns the result
as LONGINTEGER.

On May 15, 4:19*am, up2trouble <lynettesm...@gmail.comwrote:
In mysql, I have a field defined as a time stamp. *It is storing value
as 0000-00-00 00:00:00. *It to store it in seconds.

<?PHP
$entered = mktime();
echo "<INPUT TYPE='text' NAME='$entered' VALUE='$entered' SIZE='13'
READONLY>";
?>

What am i doing wrong?
Jun 2 '08 #2
I changed it to bigint didn't see long one. Now it stores a 0. It
is not taking my value from mktime(). I read your suggested material.
I understood none of it.
Jun 2 '08 #3
I don't know if this helps, but I'm trying to print unique codes for
use in a db. The problem is that when I need more codes I only want
the new ones to print out not the ones that have been already
printed. I thought that I could just set a time and say to print
codes that were generated at a time greater than the time entered.
Instead of codes, I get: Query 2 failed cause: 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 '18:47:17' at line 1.

<?PHP
if(isset($_POST['printcodes']))
{
$gettime = date("Y-m-d H:i:s", mktime());
$sql= "SELECT * FROM $db_table10 WHERE entered < $gettime";
$result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
' . mysql_error());
$num = mysql_num_rows($result);

echo "<FIELDSET><FONT SIZE='+1' COLOR='#FF0000'>These are your codes.
Just save to your desktop, then
open in Word to print.</FONT></FIELDSET";

while ($row = mysql_fetch_array ($result))
{
echo "<P STYLE='text-align: justify; width: 550px;'>This is the
anonymous id code which will allow you to take your end of class
survey.
You will need a new code for each class. ";
echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
echo "Your case sensitive code is :<BR>";
echo "<FONT SIZE='+1'><STRONG>{$row['id']}</STRONG></FONT></P>";
}
}
?>
Jun 2 '08 #4
up2trouble wrote:
I changed it to bigint didn't see long one. Now it stores a 0. It
is not taking my value from mktime(). I read your suggested material.
I understood none of it.
Please learn how to reply properly. You were not responding to
yourself. Also, please quote the relevant parts (as in here).

As to your problem - you didn't give us enough information to go on -
like the real code you're using. Additionally, you need to determine
how you want the data stored - a unix timestamp works, but there are
valid reasons for using a datetime field, also (which is off topic in a
PHP newsgroup, and should be discussed in comp.databases.mysql).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #5
On May 14, 9:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
up2trouble wrote:
I changed it to bigint didn't see long one. Now it stores a 0. It
is not taking my value from mktime(). I read your suggested material.
I understood none of it.

Please learn how to reply properly. You were not responding to
yourself. Also, please quote the relevant parts (as in here).

As to your problem - you didn't give us enough information to go on -
like the real code you're using. Additionally, you need to determine
how you want the data stored - a unix timestamp works, but there are
valid reasons for using a datetime field, also (which is off topic in a
PHP newsgroup, and should be discussed in comp.databases.mysql).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I want a timestamp to store seconds and not a date/time format. The
only thing I took out of the code was the url for my page.

<?PHP
if(isset($_POST['printcodes']))
{
$gettime = date("Y-m-d H:i:s", mktime());
$sql= "SELECT * FROM $db_table10 WHERE created < $gettime";
$result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
' . mysql_error());
$num = mysql_num_rows($result);

echo "<FIELDSET><FONT SIZE='+1' COLOR='#FF0000'>These are your codes.
Just save to your desktop, then
open in Word to print.</FONT></FIELDSET";

while ($row = mysql_fetch_array ($result))
{
echo "<P STYLE='text-align: justify; width: 550px;'>This is the
anonymous id code which will allow you to take your end of class
survey.
You will need a new code for each class. ";
echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
echo "Your case sensitive code is :<BR>";
echo "<FONT SIZE='+1'><STRONG>{$row['id']}</STRONG></FONT></P>";
}
}

?>

I should get a page of codes to print. It was working fine. However,
the problem is that when I need more codes I only want
the new ones to print out not the ones that have been already
printed. I thought that I could just set a time and say to print
codes that were generated at a time greater than the time entered.
Instead of codes, I get: Query 2 failed cause: 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 '18:47:17' at line 1.

When I create the code, I add in timestamp. I changed created to
entered and made varchar(25) in db. It doesn't keep a default value
and leaves what I entered in seconds.

$created = mktime();
$sql= "INSERT into $db_table10 (id, created) VALUES
('$random','$created')" ;

Jun 2 '08 #6
up2trouble wrote:
I don't know if this helps, but I'm trying to print unique codes for
use in a db. The problem is that when I need more codes I only want
the new ones to print out not the ones that have been already
printed. I thought that I could just set a time and say to print
codes that were generated at a time greater than the time entered.
Instead of codes, I get: Query 2 failed cause: 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 '18:47:17' at line 1.

<?PHP
if(isset($_POST['printcodes']))
{
$gettime = date("Y-m-d H:i:s", mktime());
$sql= "SELECT * FROM $db_table10 WHERE entered < $gettime";
$result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
' . mysql_error());
$num = mysql_num_rows($result);

echo "<FIELDSET><FONT SIZE='+1' COLOR='#FF0000'>These are your codes.
Just save to your desktop, then
open in Word to print.</FONT></FIELDSET";

while ($row = mysql_fetch_array ($result))
{
echo "<P STYLE='text-align: justify; width: 550px;'>This is the
anonymous id code which will allow you to take your end of class
survey.
You will need a new code for each class. ";
echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
echo "Your case sensitive code is :<BR>";
echo "<FONT SIZE='+1'><STRONG>{$row['id']}</STRONG></FONT></P>";
}
}
?>
Reading documentation can save you a lot of headaches:

PHP answer:
<?php
list($usec, $sec) = explode(" ", microtime());
print $usec . "\n";
print $sec . "\n";
?>
RESULT:
Content-type: text/html
X-Powered-By: PHP/4.3.10

microsecond - 0.82285100
unix time in sec since epoch 1210823761

No, this is not a PHP answer, but given the proposed usage, it is a
better solution... and it works...

mysqlselect UNIX_TIMESTAMP(), from_unixtime( UNIX_TIMESTAMP());
+------------------+----------------------------------+
| UNIX_TIMESTAMP() | from_unixtime( UNIX_TIMESTAMP()) |
+------------------+----------------------------------+
| 1210822584 | 2008-05-14 22:36:24 |
+------------------+----------------------------------+

you can use it in an insert statement:

insert into table values (1,'test',unix_timestamp());
mysqlcreate table aa (a bigint);
Query OK, 0 rows affected (0.02 sec)

mysql>
mysqlinsert into aa values (unix_timestamp());
Query OK, 1 row affected (0.00 sec)

mysqlselect * from aa;
+------------+
| a |
+------------+
| 1210822778 |
+------------+
1 row in set (0.00 sec)
Jun 2 '08 #7
up2trouble wrote:
On May 14, 9:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>up2trouble wrote:
>>I changed it to bigint didn't see long one. Now it stores a 0. It
is not taking my value from mktime(). I read your suggested material.
I understood none of it.
Please learn how to reply properly. You were not responding to
yourself. Also, please quote the relevant parts (as in here).

As to your problem - you didn't give us enough information to go on -
like the real code you're using. Additionally, you need to determine
how you want the data stored - a unix timestamp works, but there are
valid reasons for using a datetime field, also (which is off topic in a
PHP newsgroup, and should be discussed in comp.databases.mysql).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

I want a timestamp to store seconds and not a date/time format. The
only thing I took out of the code was the url for my page.

<?PHP
if(isset($_POST['printcodes']))
{
$gettime = date("Y-m-d H:i:s", mktime());
$sql= "SELECT * FROM $db_table10 WHERE created < $gettime";
$result = mysql_query ($sql, $connect) OR DIE ('Query 2 failed cause:
' . mysql_error());
$num = mysql_num_rows($result);

echo "<FIELDSET><FONT SIZE='+1' COLOR='#FF0000'>These are your codes.
Just save to your desktop, then
open in Word to print.</FONT></FIELDSET";

while ($row = mysql_fetch_array ($result))
{
echo "<P STYLE='text-align: justify; width: 550px;'>This is the
anonymous id code which will allow you to take your end of class
survey.
You will need a new code for each class. ";
echo "Go to xxxxxxxxxxxx. Then click on the Survey link.";
echo "Your case sensitive code is :<BR>";
echo "<FONT SIZE='+1'><STRONG>{$row['id']}</STRONG></FONT></P>";
}
}

?>

I should get a page of codes to print. It was working fine. However,
the problem is that when I need more codes I only want
the new ones to print out not the ones that have been already
printed. I thought that I could just set a time and say to print
codes that were generated at a time greater than the time entered.
Instead of codes, I get: Query 2 failed cause: 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 '18:47:17' at line 1.

When I create the code, I add in timestamp. I changed created to
entered and made varchar(25) in db. It doesn't keep a default value
and leaves what I entered in seconds.

$created = mktime();
$sql= "INSERT into $db_table10 (id, created) VALUES
('$random','$created')" ;

This was not the code in your first post - and you didn't have any code
in your second one. That is why I asked.

Your query fails because a datetime value needs to be in single quotes
in the query, i.e.

$sql= "SELECT * FROM $db_table10 WHERE created < '$gettime'";

And your other problems are SQL related - not PHP. I suggest you follow
up in comp.lang.mysql - which is where you should be asking
MySQL-related questions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
2
by: Astra | last post by:
Hi All I know an SQL Server timestamp seems to be as useful as rocking horse for show jumping, but I'm hoping you know a 'fudge' to get me round a problem or at least confirm that it isn't...
2
by: rong.guo | last post by:
Hello Group, I am having a really weird problem... Can anyone tell the difference between Query 1 and Query 2 below? Why Query 2 excludes '2/28/2005'? Many thanks! create table a...
7
by: mybappy | last post by:
Hi: I am trying to use timestamp field of SQL Server to maintain concurrency. My problem is how do I store the timestamp value in my webform. The hidden field does not work as I get some cast...
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
5
by: Prabu Subroto | last post by:
Dear my friends... I created some tables with field timestamp (datatype also timestamp). I mean, I want to have the data when each record inserted or modified in the tables. on MysQL, I just...
2
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable option or not? Below are a number of examples...
2
by: Reddog | last post by:
Hi all, I have a number of tables that I want 'timestamped' with both a modified and created 'timestamp' field. Ideally both fields should 'work if ignored' in insert and updates, thus the...
22
by: Mal Ball | last post by:
I hope I have the right forum for this question. I have an existing Windows application which uses a SQL Server database and stored procedures. I am now developing a web application to use the same...
7
by: JJ | last post by:
How do I set one field to have the updated timestamp, and another to have the created timestamp? I want to do this directly from code generated from DB Designer if possible?! JJ
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.