time of day

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

time of day

Post by irealms »

I'm trying to insert the current time into a database in the TIME format, i see to keep getting it in seconds atm. At present i've tried this:

Code: Select all

<?php
$time = gettimeofday();
		$date = date('y-m-d');
		$send = "INSERT INTO e_post (id,groupname,username,whofrom,date,time,readstate,subject,message) VALUES ('','$_SESSION[groupname]','$_POST[recip]','$_SESSION[valid_user]','$date','sec_to_time($time[sec])','','$_POST[newsub]','$_POST[newmsg]')";
		$sent = mysql_query($send, $db_conn) or die("Query send failed".mysql_error());
		echo '<p class="main">Message sent.</p>';

?>
first it inserted a time of 859 hours and next time blank :(
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post by greenhorn666 »

Code: Select all

'sec_to_time($time[sec])'
What is that suppose to be?
And, sorry if I sound like a smarta**, but shouldn't you RTFM first?

Of course that way you are on your way to be master and no more 'Programmer'... But shouldn't you try to become a coder first?
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post by irealms »

well the status comes as amount of posts, i have posted a lot when asking questions i can't answer myself from the manual pages. Same as everyone else here does.

Sorry that asking questions on a questions forum bothers you, i have been using php 6 months and am learning as i go. When possible i answer others questions.

The sec_to_time is a mysql function i've used to convert time previously :

"SELECT sec_to_time(time_to_sec(endtime) - time_to_sec(starttime)) AS total_time FROM timesheets WHERE groupname='$_SESSION[groupname]' AND username='$_SESSION[valid_user]' AND tid='$trow[tid]'";

i was trying it another way for this.

Sorry to bother you with my inane dribble :)
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post by greenhorn666 »

You are not bothering me... That wasn't my point (and thanks I got the avatar or how it's called thing :) )

Concerning the sec_to_time($time[sec]), my question was more about the $time[sec] part... What's in there (I got the sec_to_time from the FM in the RTFM ;), I use postgres, not mysql; hence I looked up).
So what is in this var? don't tell me you put time() in there?
Anyhow, why don't you just put $time = date("H:i"); in it? and put the time formatted?

Or do I miss a point here?
Last edited by greenhorn666 on Thu Aug 21, 2003 6:44 am, edited 1 time in total.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post by irealms »

fixed it now with date function, lol. Sorry for my rash posting here, we have to end coding friday to write a 15,000 word report so i'm rushing. Normally since i started becoming more familiar with things i only post when i'm really stuck.

The fact i'm stressed and rushing means i end up not thinking straight, sure you've been there before :)

We've had 2 months to do what was originally expected to take 8 months and it's my first attempt at a php site on the scale needed.

just got to sort the daylight saving time now, thought i was an hour closer to going home, lol
Post Reply