Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

combine date and time in an array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

combine date and time in an array

Postby Divyatamizh » Wed Apr 10, 2013 11:53 pm

hi friends,
i have to find the Date and time worked by an employee in a month. And i found it.
Now i have to show the these details when i choose any two dates of a month.

example:

from_date=" 2013-04-01";
to_date ="2013-04-05";

AND worked dates and time respectively are:

$values[] =" 2013-04-02, 2013-04-04 " ;
$time[]=" 20:40:00 , 10:00:40;

total dates===> $num_dates[]=" 2013-04-01, 2013-04-02,2013-04-03, 2013-04-04, 2013-04-05 " ;

i want the output as:

2013-04-01 - Not Available
2013-04-02 - 20:40:00
2013-04-03 - Not Available
2013-04-04 - 10:00:40
2013-04-05 - Not Available


here is the code which i get
Code: Select all

foreach($num_dates as $key=>$data)
{

//echo $key;

   if(in_array($data,$values))
      {
   

   print $data."  <strong>time</strong> " ;
   }
     else
      {
   print $data."  <strong>Not Available</strong>";
      }
   print "<br>";

}


from the above code i get output as:

2013-04-01 Not Available
2013-04-02 time
2013-04-03 Not Available
2013-04-04 time
2013-04-05 Not Available

help me to place the time for respective dates
could someone help me to solve the problem.
Divyatamizh
New php-forum User
New php-forum User
 
Posts: 9
Joined: Sun Mar 03, 2013 11:56 pm

Re: combine date and time in an array

Postby johnj » Thu Apr 11, 2013 12:10 am

When you show the date, show the respective time, you have the time in the array.
e.g. echo $data[0].' '.$time[0]
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: combine date and time in an array

Postby Divyatamizh » Thu Apr 11, 2013 1:15 am

i tried doing that, if the process is done manually means its ok. but when i retrieve the values from database i am not getting the required output.
Divyatamizh
New php-forum User
New php-forum User
 
Posts: 9
Joined: Sun Mar 03, 2013 11:56 pm

Re: combine date and time in an array

Postby sandeep605085 » Thu Apr 11, 2013 10:53 am

its very easy to display date and time together.
let me know the database query from where you are getting the date and time.
and the date and time example the way it is saved in the database.

for now what i am thinking is that get date and time together and then using date() function we can manipulate it to display as we like.
User avatar
sandeep605085
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron