Jump to content

[SOLVED] edit time stamp field


EchoFool

Recommended Posts

Hey

 

I have a query which i want to update a time stamp in one of my field to be X amount of days different to what it is.

 

So what i mean is this:

 

Say the timestamp says:  2008-01-01 00:00:00

 

Now i want to make it 14 days before that timestamp using a query...at first i thought that should be simple but then i realised it isn't because the year and month would become 2007-12 etc etc

 

 

Can this be done in one simple update query..if not how can i do such maths to a timestamp like that?

Link to comment
Share on other sites

I also have a question regarding Time. I have a database where the opening hours and ending hours of a shop are stored with the datatype TIME. Now I have the following code:

 

function isOpenNow($account)
{
$toreturn;
$today = date("w");
echo $today;
$hour = date("G:i:s");
echo $hour;
$query_getHours = "SELECT open, whole_day, morning, start_morning, end_morning, afternoon, start_afternoon, end_afternoon FROM openinghours WHERE account_id = ".$account." AND day = ".$today;
$result_getHours = mysql_query($query_getHours) or die(mysql_error());
if(mysql_result($result_getHours, 'open') == true)
{
if(mysql_result($result_getHours, 'whole_day') == true)
{
	// now we only need to check starting hours and end hours
	$starthour = mysql_result($result_getHours, 'start_morning');
	$endhour = mysql_result($result_getHours, 'end_afternoon');
	if($starthour < $hour < $endhour)
	{
		echo "Open for the whole day and you can still go";
	}
}
}
else
{
echo "Closed";
}
}

 

Now I get the error:

Parse error: syntax error, unexpected '<' in /data/vhome/vhost0098/http/search.php on line 181

Line 181 is where I make the comparisation (if($starthour < $hour < $endhour)).

So < is an unexpected character in my code?

I know that $hour has the right format because I echo'd it and ik came out like in the database e.g. 21:28:41

 

Should I compare Time's otherwise?

Link to comment
Share on other sites

I also have a question regarding Time. I have a database where the opening hours and ending hours of a shop are stored with the datatype TIME. Now I have the following code:

 

function isOpenNow($account)
{
$toreturn;
$today = date("w");
echo $today;
$hour = date("G:i:s");
echo $hour;
$query_getHours = "SELECT open, whole_day, morning, start_morning, end_morning, afternoon, start_afternoon, end_afternoon FROM openinghours WHERE account_id = ".$account." AND day = ".$today;
$result_getHours = mysql_query($query_getHours) or die(mysql_error());
if(mysql_result($result_getHours, 'open') == true)
{
if(mysql_result($result_getHours, 'whole_day') == true)
{
	// now we only need to check starting hours and end hours
	$starthour = mysql_result($result_getHours, 'start_morning');
	$endhour = mysql_result($result_getHours, 'end_afternoon');
	if($starthour < $hour < $endhour)
	{
		echo "Open for the whole day and you can still go";
	}
}
}
else
{
echo "Closed";
}
}

 

Now I get the error:

Parse error: syntax error, unexpected '<' in /data/vhome/vhost0098/http/search.php on line 181

Line 181 is where I make the comparisation (if($starthour < $hour < $endhour)).

So < is an unexpected character in my code?

I know that $hour has the right format because I echo'd it and ik came out like in the database e.g. 21:28:41

 

Should I compare Time's otherwise?

 

Think its cos your suppose to put:

 

(if($starthour < $hour && $starthour< $endhour))

Link to comment
Share on other sites

I also have a question regarding Time. I have a database where the opening hours and ending hours of a shop are stored with the datatype TIME. Now I have the following code:

 

function isOpenNow($account)
{
$toreturn;
$today = date("w");
echo $today;
$hour = date("G:i:s");
echo $hour;
$query_getHours = "SELECT open, whole_day, morning, start_morning, end_morning, afternoon, start_afternoon, end_afternoon FROM openinghours WHERE account_id = ".$account." AND day = ".$today;
$result_getHours = mysql_query($query_getHours) or die(mysql_error());
if(mysql_result($result_getHours, 'open') == true)
{
if(mysql_result($result_getHours, 'whole_day') == true)
{
	// now we only need to check starting hours and end hours
	$starthour = mysql_result($result_getHours, 'start_morning');
	$endhour = mysql_result($result_getHours, 'end_afternoon');
	if($starthour < $hour < $endhour)
	{
		echo "Open for the whole day and you can still go";
	}
}
}
else
{
echo "Closed";
}
}

 

Now I get the error:

Parse error: syntax error, unexpected '<' in /data/vhome/vhost0098/http/search.php on line 181

Line 181 is where I make the comparisation (if($starthour < $hour < $endhour)).

So < is an unexpected character in my code?

I know that $hour has the right format because I echo'd it and ik came out like in the database e.g. 21:28:41

 

Should I compare Time's otherwise?

 

Don't hijack threads. Create your own.

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.