Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<b>PHP date problem</b> 1

Status
Not open for further replies.

kathanon

Technical User
Jan 29, 2002
218
GB
This is a newbie question, I am having some problems with a site I am looking after. There is a list page connected with a detail page on which there is a problem with the time. If I add 00:00 on the content management page, it adds this to the list page with the main events, however on the detail page this shows as 12:00.

Sorry if this is a really obvious thing and also if I have not pasted the right bits of code. Here is the code from the detail page

<?php
$pubdate = $row_revs['evdate'];
$formdate = date('l, jS F Y',$pubdate);
echo $formdate;
?>
</td>
</tr>
<tr>
<td align="right" valign="top" class="formlabelhead">Time:</td>
<td>
<?php
$formdate = date('g.i a',$pubdate);
echo $formdate;

Here is the code from the list page,

$pubdate = $row_revs['ev_date'];
$i = substr($pubdate,14,2);
$h = substr($pubdate,11,2);
$d = substr($pubdate,8,2);
$m = substr($pubdate,5,2);
$y = substr($pubdate,0,4);
echo $d."/".$m."/".$y;
?>
</td>
<td class="headsubtitle"><?php echo $h.":".$i; ?></td>

Thank you for any help. The detail page will only show the wrong time for 00:00 for all other times it shows the right hour. I am wondering if this might be because a previous page in the add/edit part of the site gives all of the times up to and including 23:00 but nothing for 24:00 Have pasted the "add event" code for the time below

<select name="hrs" id="hrs">
<option value="0" <?php if ($h=="00") { echo "selected"; } ?>>00</option>
<option value="1" <?php if ($h=="01") { echo "selected"; } ?>>01</option>
<option value="2" <?php if ($h=="02") { echo "selected"; } ?>>02</option>
<option value="3" <?php if ($h=="03") { echo "selected"; } ?>>03</option>
<option value="4" <?php if ($h=="04") { echo "selected"; } ?>>04</option>
<option value="5" <?php if ($h=="05") { echo "selected"; } ?>>05</option>
<option value="6" <?php if ($h=="06") { echo "selected"; } ?>>06</option>
<option value="7" <?php if ($h=="07") { echo "selected"; } ?>>07</option>
<option value="8" <?php if ($h=="08") { echo "selected"; } ?>>08</option>
<option value="9" <?php if ($h=="09") { echo "selected"; } ?>>09</option>
<option value="10" <?php if ($h=="10") { echo "selected"; } ?>>10</option>
<option value="11" <?php if ($h=="11") { echo "selected"; } ?>>11</option>
<option value="12" <?php if ($h=="12") { echo "selected"; } ?>>12</option>
<option value="13" <?php if ($h=="13") { echo "selected"; } ?>>13</option>
<option value="14" <?php if ($h=="14") { echo "selected"; } ?>>14</option>
<option value="15" <?php if ($h=="15") { echo "selected"; } ?>>15</option>
<option value="16" <?php if ($h=="16") { echo "selected"; } ?>>16</option>
<option value="17" <?php if ($h=="17") { echo "selected"; } ?>>17</option>
<option value="18" <?php if ($h=="18") { echo "selected"; } ?>>18</option>
<option value="19" <?php if ($h=="19") { echo "selected"; } ?>>19</option>
<option value="20" <?php if ($h=="20") { echo "selected"; } ?>>20</option>
<option value="21" <?php if ($h=="21") { echo "selected"; } ?>>21</option>
<option value="22" <?php if ($h=="22") { echo "selected"; } ?>>22</option>
<option value="23" <?php if ($h=="23") { echo "selected"; } ?>>23</option>
</select>



 
Don't worry about the missing "24" in the list. When you're dealing with a 24-hour clock system, there is no 24th hour -- it is the same as the zeroth hour, and "00" is in the list.


Unfortunately, you have not pasted the necessary code. The SELECT tag is named "hrs". The problem will likely be in code that manipulates that value.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thank you,

I do feel a bit dumb asking all this but am in at the deep end at the moment.

As far as I can make out, at the beginning of the page there is an SQL command which gets the information added to the database by the content management system,

SELECT ev_ID, ow_title, ev_type, ev_title, ev_loc, ev_url, ev_info, ev_contact, ev_dir, UNIX_TIMESTAMP(ev_date) as evdate FROM events, owners WHERE owners.ow_ID=events.ev_owner AND ev_ID=%s",$colname_revs)

Then there is some php which will list information about the event and the time and date code is pasted below.

What puzzles me is that on the list page it shows the time as entered in the content management page but on this detail page the time shows 00:00 as 12:00.

I can only see one global variable on this page for the actual event ID and then all the rest seems to apply to the database info. Here is the bit that prints the date and time

$pubdate = $row_revs['evdate'];
$formdate = date('l, jS F Y',$pubdate);
echo $formdate;
?>
</td>
</tr>
<tr>
<td align="right" valign="top" class="formlabelhead">Time:</td>
<td>
<?php
$formdate = date('g.i a',$pubdate);
echo $formdate;
?>

Really sorry if I have still missed the plot here, am desperately trying to learn php while also learning to maintain a site
 
The problem may not be in the code that fetches data from the database. It could also be in the code that inserts the new event into the database. If for no other reason than to be methodical, we should look at that code first.

In the script to which the form containing the SELECT tag named "hrs", there will be code which manipulates the value entered.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks again,

Tomorrow I will get that code and past it here. I don't have access to it from here. I had thought it might be this page as the date shows correctly on the main listing page.

Kathy
 
tathanon said:
date shows correctly on the main listing page

You didn't say that before.

In such case, it's probably this line:

$formdate = date('g.i a',$pubdate);

which is displaying the 12-hour-clock hour. The online manual says that the "g" will give you a value of 1 through 12. "00" hours and "12am" are one and the same.

On the main display page which correctly displays the value, what date format is used?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I am sure that must be it, I also noticed that on the contact management page, when I the time as 19.30 it shows on the detail page as 5.30, so maybe all I need to do is to change the formatting of the time.

I have removed the code that outputs the the time for the moment. I don't have the other code with me as I am at home now.

Thank you very much for your time and help. I will let you know what happens
 
I have just tried changing it at home on my local system and G gives me the right result!

Thank you very much
 
Maybe you have to use this code:

$a = mktime() ; //gives a numeric value, put in your table

//=========================================

//$a comes from your table
$var = strFtime('%c', $a);
echo $a . "---" . $var;

Now a 24-hours time will be showed!

Michelle.
 
I guess your problem is already solved?

I saw your code though and was a little ... distracted by the many <option>s. Why didn't you put it in a loop?

Code:
<?php for($i = 0; $i < 24; $i++) { ?>
  <option value="0"<?php if ($h == $i) { echo " selected"; } ?>>
    <?php echo $i; ?>
  </option>
<?php } ?>

haslo@haslo.ch - www.haslo.ch​
 
Hm, can't fix my error, no "edit post" option :) of course, the value has to be not "0" but "<? echo $i ?>"...

haslo@haslo.ch - www.haslo.ch​
 
Thank you both,

It is not my own code (although thank you for being tactful haslo (distracted is a good way to describe it!) I have inherited the maintenance of the site and am gradually working my way through a mixture of beginner's php books, writing my own snippets of php and trying to work out teething problems with the actual pages.


My latest problem is that in the members' area (which uses cookies)the page expires and will not go back without refreshing it once someone has logged in. I am wondering if this is a setting in the php.ini file or something to do with the code

Mind you, nothing like solving a few problems to learn quickly I think.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top