473,549 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1886
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...@g mail.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><FON T 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_arr ay ($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'><STRO NG>{$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*******@attgl obal.net
=============== ===

Jun 2 '08 #5
On May 14, 9:54 pm, Jerry Stuckle <jstuck...@attg lobal.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...@attgl obal.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><FON T 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_arr ay ($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'><STRO NG>{$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','$cr eated')" ;

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><FON T 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_arr ay ($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'><STRO NG>{$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...@attg lobal.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...@attg lobal.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><FON T 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_arr ay ($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'><STRO NG>{$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','$cr eated')" ;

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*******@attgl obal.net
=============== ===

Jun 2 '08 #8

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

Similar topics

13
9273
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 three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted...
2
10945
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 possible. I have 2 tables, one called ACCOUNTS and one called STOCK. These tables have the usual ints, varchars, etc and have a timestamp field as...
2
5173
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 (ApplicationID int ,timestamp datetime)
7
4045
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 error. If I can not store the value, how should I return the timestamp to the database (with other values) to compare with the current timestamp to...
2
720
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 columns, and ultimately feed the result into a graph-drawing web thingy. I'm trying a few different ways to get what seems to be the same data, and seeing...
5
2696
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 need to define the column (field) with datatype "timestamp" and that's all. each time new record inserted than the timestamp value will be inserted...
2
4332
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 showing what I am experiencing. The last own shows how converting timestamps to dates and then ordering doesn't give you the order you want. Maybe you...
2
4478
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 following is fine for a modified timestamp field tsm: tsm timestamp default current_timestamp on upate current_timestamp
22
6392
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 database. The original Update and Delete SP's all use a timestamp for concurreny checking. I am trying to use the same Update SP from my...
7
6093
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
0
7472
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7986
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6074
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5391
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3518
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.