Current location: Hot Scripts Forums » Programming Languages » PHP » time


time

Reply
  #1 (permalink)  
Old 08-24-10, 11:13 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
time

How i will enter any time (am, pm) into a database
I have two fields Start Time and End Time

$query_manual1 = "INSERT INTO times(StartTime, EndTime)
VALUES ('TIME: Manual Time', '12:10:00')";

IS THIS CORRECT??

AND IT IS POSSIBLE TO INSERT THE DATES WITH SOME TIME PICKER?? INSTEAD MANUALLY

THANK YOU
Reply With Quote
  #2 (permalink)  
Old 08-27-10, 09:16 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
You could use the jQuery plugin datepicker/timepicker.

datepicker
timepicker add on

As for the start and end time, your column should be a timestamp type, which takes the form of.

YYYY-MM-DD H:M:S

or,
PHP Code:

date('Y-m-d H:i:s'); 

PHP Code:

$start = (isset($_POST['start') && preg_match('~[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}\s[a|p]m)?~',$_POST['start'])) ? $_POST['start'] : die('Starting Time is out of sequence');

$end = (isset($_POST['end']) && preg_match('~[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}\s[a|p]m)?~',$_POST['end'])) ? $_POST['end'] : die('Ending Time is out of sequence');
$startTime date('Y-m-d H:i:s',strtotime($start));
$endTime date('Y-m-d H:i:s',strtotime($end));
$sql "INSERT INTO times(StartTime,EndTime) VALUES ('$startTime','$endTime')"
Reply With Quote
  #3 (permalink)  
Old 08-28-10, 02:35 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Why not use a TIMESTAMP field, and insert a time() value? That way you have several mysql function available to manipulate the time data (such as DATEDIFF, TIMESTAMPDIFF, DATE_FORMAT, etc.)
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #4 (permalink)  
Old 08-28-10, 08:00 AM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
thank you!!! i have another question
i have this mysql statement originally:

$sqlEvent = "select starttime, endtime FROM eventcalender where eventDate='".$month."/".$day."/".$year."';

which working find, but now i have a field call tutorid then i want to populate the eventDate of each tutor.

$sqlEvent = "select starttime, endtime FROM eventcalender where eventDate='".$month."/".$day."/".$year."' AND tutorid = '$tutorid'";

BUT IT GIVES ME AND ERROR, CAN YOU HELP ME WITH THIS?? THANK YOU IN ADVANCED
Reply With Quote
  #5 (permalink)  
Old 08-28-10, 11:01 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Please do not shout (capital letters), we can hear you perfectly even if you don't shout!

What's the error? What does your mysql table look like?
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #6 (permalink)  
Old 08-28-10, 04:07 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
this is the mysql table

table eventcalender

ID int(11) No None auto increment
Title varchar(65) latin1_swedish_ci No None
Detail varchar(255) latin1_swedish_ci No None
eventDate varchar(10) latin1_swedish_ci No None
dateAdded date No None
starttime varchar(265) latin1_swedish_ci No None
endtime varchar(265) latin1_swedish_ci No None
status int(1) No None
tutorid int(8) No None


This is the code, it works, but when i am trying to add the tutorid, it does not



PHP Code:

<?php

 mysql_connect
("localhost""checkbox""checkbox") or die (mysql_error());
 
 echo 
"Connected to Mysql<br/><hr/>";
 
 
mysql_select_db("checkbox") or die (mysql_error());
 
 echo
"Connected to database<br/><hr>";

?>

 <html>
 <head>
    <script>
          function goLastMonth(month, year){
               if(month == 1) {
                  --year;
                  month = 13;
               
               }
               --month
               var monthstring= ""+month+"";
               var monthlength = monthstring.length;
               if(monthlength <=1){
                monthstring = "0" + monthstring;
               
               
               }
               document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
          }
    
         function goNextMonth(month, year){
              if(month == 12) {
                     ++year;
                     month = 0;
              
              }
              ++month
               var monthstring= ""+month+"";
               var monthlength = monthstring.length;
               if(monthlength <=1){
                monthstring = "0" + monthstring;


               }
              document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
         }
    </script>
    <style>
         .today{
         background-color: #00ff00;

         }
         .event{
           background-color: #FF8080;
         }
         .beforeevent{
           background-color: #B0B0B0;
         }
         .afterevent{
         background-color:#FFFF00;

    </style>
 </head>

 <body>
          <?php
          
if (isset($_GET['day'])){
                
$day $_GET['day'];
          }   else {
                     
$day date("j");
          }
           if(isset(
$_GET['month'])){
              
$month $_GET['month'];
           
           } else {
           
                
$month date("n");
           }
           if(isset(
$_GET['year'])){
            
$year $_GET['year'];
            }else{
            
$year date("Y");
           
           }

                 
//calender varibble
                
$currentTimeStamp strtotime"$day-$month-$year");
                
$monthName date("F"$currentTimeStamp);
                
$numDays date("t"$currentTimeStamp);
                
$counter 0;
                 
                
          
?>

 
          <table border='0'>
                <tr>
                      <td bgcolor='#000000'><input style='width:35px;' type='button'  value='<'name='previousbutton' onclick ="goLastMonth(<?php echo $month.",".$year?>)"></td>
                      <td colspan='5'><?php echo $monthName.",  ".$year?></td>
                      <td bgcolor='#000000'><input style='width:35px;' type='button' value='>'name='nextbutton' onclick ="goNextMonth(<?php echo $month.",".$year?>)"></td>

                </tr>
                 <tr>
                      <td width='35px' bgcolor='#000000'><font color="#FFFFFF">Sun</td>
                      <td width='35px' bgcolor='#000000'><font color="#FFFFFF">Mon</td>
                      <td width='35px' bgcolor='#000000'><font color="#FFFFFF">Tue</td>
                      <td width='35px' bgcolor='#000000'><font color="#FFFFFF">Wed</td>
                      <td width='35px' bgcolor='#000000'><font color="#FFFFFF">Thu</td>
                      <td width='35px' bgcolor='#000000'><font color="#FFFFFF">Fri</td>
                      <td width='35px' bgcolor='#000000'><font color="#FFFFFF">Sat</td>
                </tr>
          
              <?php
                
echo "<tr>";
                 for(
$i 1$i $numDays+1$i++, $counter++){
                   
$timeStamp strtotime("$year-$month-$i");
                   if(
$i == 1) {
                       
$firstDay date("w"$timeStamp);
                       for(
$j 0$j $firstDay$j++, $counter++) {
                       
//blank space
                       
echo "<td>&nbsp;</td>";
                       }
                   }
                      if(
$counter == 0) {

                             echo
"</tr><tr>";

                      }
                      
$monthstring $month;
                      
$monthlength strlen($monthstring);
                      
$daystring $i;
                      
$daylength strlen($daystring);
                      if(
$monthlength <= 1){
                         
$monthstring "0".$monthstring;
                      
                      
                      }
                      if(
$daylength <=1){
                        
$daystring "0".$daystring;
                      }
                      
                      
$todaysDate date("m/d/Y");
                      
$dateToCompare $monthstring'/' $daystring'/' $year;
                      
                        echo 
"<td align='center' ";
                        if (
$todaysDate == $dateToCompare){
                            echo 
"class ='today'";
                            }

                        if(
$todaysDate $dateToCompare){
                            echo 
"class ='beforeevent'";
                        }

                        else{
                         
$sqlCount "select * from eventcalender where  eventDate='".$dateToCompare."'";
                         
$noOfEvent mysql_num_rows(mysql_query($sqlCount));
                         if(
$noOfEvent >= 1){
                            echo 
"class='event'";

                         }
                        }
                       echo 
"><a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true'>".$i."</a></td>";
                 }
                
                echo 
"</tr>";
              
?>
          </table>
         <?php

              $sqlEvent 
"select starttime, endtime, tutorid FROM eventcalender where eventDate='".$month."/".$day."/".$year."'";

              
$resultEvents mysql_query($sqlEvent);
                echo
"<form >";
                echo 
"<table border='1'>";

                  echo
"<tr><td colspan='2'>Make an Appointment with your Tutor</td></tr>";
                echo
"<th width='35px'>Start Time</th>";
               echo
"<th width='35px'>End Time</th>";

               while (
$events mysql_fetch_array($resultEvents))
               {



               echo
"<tr><td aling='center' width='35px'>".$events['starttime']."</td><td>".$events['endtime']."</td></tr>";
               }

               echo
"<tr><td width='35px'>Name:</td><td colspan='2'><input type='text' size='35'></td></tr>";
               echo
"<tr><td width='35px'>Email:</td><td td colspan='2'><input type='text' size='35'></td></tr>";
               echo
"<tr><td width='35px'>Phone:</td><td td colspan='2'><textarea rows='2' ></textarea></td></tr>";
               echo
"</form>";
         
?>
 </body>
 </html>
thank you for ur help

Last edited by UnrealEd; 08-28-10 at 04:52 PM. Reason: fixed [php] tags
Reply With Quote
  #7 (permalink)  
Old 08-28-10, 04:47 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
this is sometime similar that i wanna acomplish

Time Slots Booking Calendar script
Reply With Quote
  #8 (permalink)  
Old 08-28-10, 04:55 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
what's the error you're facing?
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #9 (permalink)  
Old 08-28-10, 06:05 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
I cant get the mysql statement to work I WANT TO SHOW EVERY CALENDER FOR EVERY TUTOR.
SO WHEN PEOPLE CHOOSE A TUTOR BRING HIS OWN CALENDAR HOURS... THEN IT WILL POPULATE THE TUTOR WITH HIS RESPECTIVE HOURS AVAILABLE FOR THE DAY... THEN IF THE CUSTOMER WANTS TO MAKE AN APPOINTMENT IT JUST CLICK A CHECK BOX AND MAKE THE CHANGES IN THE DB. Then if someone else require the same tutor when they click the same day it will shows the schedule with the hours available (unchecked box) and unavailable (checkedbox)
Reply With Quote
  #10 (permalink)  
Old 08-28-10, 06:08 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
this is the error i have..

Notice: Undefined variable: tutorid in C:\wamp\www\calendar3\calendar.php on line 174

Tutors Schedule for Today
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\calendar3\calendar.php on line 184

and this is the mysql statement

$sqlEvent = "SELECT starttime, endtime,tutorname FROM eventcalender where eventDate='".$month."/".$day."/".$year."' AND tutorname =$tutorid";
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Changing server time with a PHP script? Shto PHP 7 03-23-09 11:55 AM
Convert to time from a string Godwin PHP 2 09-26-06 12:25 AM
having Loop issues, help... Advanced todayscoffee PHP 2 02-27-06 12:36 AM
Super class seo services extreme90 General Advertisements 0 12-28-05 12:45 PM


All times are GMT -5. The time now is 08:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.