473,493 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Timestamp problem

I use PHP 4.4.0 and MySQL 4.0.26 and Mozilla Firefox.

This code:

$dummy = strtotime("-13 hour");
$csql = "update citc_weather
set imagepath = '$p_image',
text = '$p_text',
lastupdated = $dummy
where id = 1";

where lastupdated is of timestamp(14), doesn't work.

All that gets posted in lastupdated is 00000000000000.

Oct 3 '05 #1
5 1228
Try to use

$dummy = strtotime("-13 hour");
$csql = "update citc_weather
set imagepath = '$p_image',
text = '$p_text',
lastupdated = FROM_UNIXTIME($dummy)
where id = 1";

Oct 4 '05 #2
Try to use

$dummy = strtotime("-13 hour");
$csql = "update citc_weather
set imagepath = '$p_image',
text = '$p_text',
lastupdated = FROM_UNIXTIME($dummy)
where id = 1";

Oct 4 '05 #3
plz check the datatype of lastupdated column in your mysql database
table 'citc_weather'. If it was set to 'timestamp' type, it will never
let you modify it explicitly, so if you want to change it
programmatically you need to change its type to datetime.

I 've also come across this kinda error once when whatever I was trying
to insert or updating timestamp type column, I got 0000000000 as a
result

Hope it helps

Thanks

Regards
IndianTroy

Oct 4 '05 #4
Thanks! It worked!

Here is the follow-up problem:

I now have 20051004093359, say, in the lastupdated field which is
timestamp(14).

However,

<?php
require 'citc_connect.php';
$csql = 'select
imagepath,
text,
lastupdated
from citc_weather';
$result = mysql_query($csql);
$nrows = mysql_affected_rows();
if ($nrows == -1) {echo 'Unexpected error in the query:<br/>';
die($csql);};
$row = mysql_fetch_array($result);
?>

<html>
<body>
<p>Last updated: <?php echo $row['lastupdated']; ?> </p>
<p>Last updated: <?php echo date('l j-M h:i A', $row['lastupdated']);
?> </p>
</body>
</html>

Gives:

Last updated: 20051004093359
Last updated: Tuesday 19-Jan 11:14 AM

The last line should read:

Last updated: Tuesday 4-Oct 9:33 AM

What am I doing wrong?

Oct 4 '05 #5
I found what was missing.

This works:

$csql = 'select
imagepath,
text,
lastupdated,
UNIX_TIMESTAMP(lastupdated) as lupdated
from citc_weather';

I tested the insert and select code with the 'lastupdated' field as
data type timestamp and as datetime. It worked in both cases.

Thanks for the help!

Oct 4 '05 #6

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

Similar topics

2
32405
by: Ben | last post by:
I would like to use php to query a database and retrieve a unix timestamp. The problem is that mysql is storing the data in the date format and not a timestamp. I am sure that I can amend my...
2
10935
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
5170
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...
2
16201
by: Alex | last post by:
Hi all, Got a small problem here. I have a number of web caches here that generate loads and loads of log files and instead of keeping them for analysis I want to write them to a db/2...
6
2502
by: Robert Schuldenfrei | last post by:
Dear NG, As expected, when I went to implement TIMESTAMP, I failed. With the help of Kevin Yu, I got the 2 code segments at the bottom working using a WHERE clause that checks all columns. ...
1
7978
by: Roger Twomey | last post by:
I have a database that I don't want to lock. I decided that before any updates can occur I would check a timestamp value and ensure that nobody else updated before I did (avoiding the 'last update...
7
4034
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...
0
1644
by: presley2 | last post by:
Hi, I want to create an auto creation date and update date in my mysql table. I am using the "MySQL Cookbook" approach, using the TIMESTAMP field which basically is: - create 2 new fields in the...
5
5356
by: pankaj_wolfhunter | last post by:
Greetings, In Sybase, a timestamp column is automatically loaded by the DB engine and its in some hex format. This is shown below id timestamp_value ----------- ------------------ 1...
22
6386
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...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7195
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...
1
6873
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...
0
7367
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...
0
5453
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,...
1
4889
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...
0
3088
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...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
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...

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.