Jump to content

[SOLVED] Start date end date


forumnz

Recommended Posts

Hi I am creating a simple auction site.

 

There will be a start date which I think will be a timestamp and an end date. How can I do code the end date so that it is $days until it closes?

 

I am not asking for code (although that may be helpful) I am asking for an explanation.

 

Thanks a lot,

Sam.

Link to comment
Share on other sites

Basically I want to find the easiest way to store a start and end date in a db.

 

If the start date is something like 2007-10-10 22:13:46 then then end date should be (for a 7 day auction) 2007-10-17 22:13:46.

 

I also need to be able to code it so that I can display the time left (e.g. 6h 18m). Im not asking for an explanation on that one, but the first problem must accomodate for that.

 

So, sorry about the confusion, what is the best way now?

 

Thanks very much,

Sam.

Link to comment
Share on other sites

I just made this and it displays start date and end date (7days).

 

Can you tell me if I coded it well please?

 

Sam.

 

<?php 

$d = date("d");
echo date('d m Y G:i:s');
$sd = date('$d m Y G:i:s');

echo "<br /><br />";
$dd = $sd + (7+$d);

echo $dd . date(' m Y G:i:s');
?>

Link to comment
Share on other sites

It would be better as DATETIME fields to include the h:m:s element too

<?php
$saleitem = 'widget extractor';
$duration = 7;

$sql = "INSERT INTO auction (item, startdate, enddate)
        VALUES ('$saleitem', NOW(), NOW()+INTERVAL $duration DAY)"

?>

 

For the time left, you need to compare the end datetime with the current datetime

<?php 
$endtime = strtotime ($db_enddate);   // enddate from the db record for the item
$seconds_left = $endtime - time();

$days_left = floor($seconds_left / 86400);
$seconds_left = $seconds_left % 86400;

$hours_left = floor($seconds_left / 3600);
$seconds_left = $seconds_left % 3600;

$mins_left = floor($seconds_left / 60);
$seconds_left = $seconds_left % 60;

echo "$days_left days $hours_left hours $mins_left minutes $seconds_left seconds left";
?> 

Link to comment
Share on other sites

Hi and thanks, this is what I have:

 

<?php

$duration = 7;

//Connect to mysql server
$link=mysql_connect("localhost","@@@",@@@");
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db=mysql_select_db("bbm@@@rs");
if(!$db) {
	die("Unable to select database");
}

$qry="INSERT INTO auctions (start, end)
        VALUES (NOW(), NOW()+INTERVAL $duration DAY)";


?>

 

It hasn't inserted into db though. Am I doing something wrong.

 

The db has start and end both as time stamps. The start one is a current one. Should they be different?

 

Sam.

Link to comment
Share on other sites

i noticed a slight syntax error try this:

 

 


<?php

$duration = 7;

//Connect to mysql server
$link=mysql_connect("localhost","@@@","@@@");
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db=mysql_select_db("bbm@@@rs");
if(!$db) {
	die("Unable to select database");
}

$qry="INSERT INTO auctions (start, end)
        VALUES (NOW(), NOW()+INTERVAL $duration DAY)";


?>




Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.