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
https://forums.phpfreaks.com/topic/139459-solved-edit-time-stamp-field/
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?

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))

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.