473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to tale only hour from the date time

250 100+
I want to take only the hour from the date time field. For that first i apply the explode.[PHP]$Query1 = explode(" ",$row['Date']);[/PHP]
output:13:30:0013:30:0016:20:0016:20:00(This include hour:minutes:seconds)
And now i want to extract only first 2 digit(hour).
ex:13,13,16,16
HOw can i do that? Please help me.
Jul 24 '08 #1
3 9402
Brosert
57
try
Expand|Select|Wrap|Line Numbers
  1. date('h',$row['Date']);
  2.  
if the sql stores the date as a single int....
if the Date field is a String representation, you may like to first convert to a time object, using:
Expand|Select|Wrap|Line Numbers
  1. $temp=strtotime($row['Date']);
  2. $hour=date('h',$temp);
  3.  
note: h will give you the hour in 12 hr format - H will give 24hr format

you could also try to extract the hour yourself by manipulating the string.....

http://us3.php.net/date
Jul 24 '08 #2
ghjk
250 100+
try
Expand|Select|Wrap|Line Numbers
  1. date('h',$row['Date']);
  2.  
if the sql stores the date as a single int....
if the Date field is a String representation, you may like to first convert to a time object, using:
Expand|Select|Wrap|Line Numbers
  1. $temp=strtotime($row['Date']);
  2. $hour=date('h',$temp);
  3.  
note: h will give you the hour in 12 hr format - H will give 24hr format

you could also try to extract the hour yourself by manipulating the string.....

http://us3.php.net/date




I did it. But got only 20. This is my code.[PHP]
$Date= "13:30:0013:30:0016:20:0016:20:00";
date('H',$row['Date']);

$temp=strtotime($row['Date']);
$hour=date('H',$temp);
echo "$hour";[/PHP]
Jul 25 '08 #3
Brosert
57
Why are there 4 seperate Times in the field??

I think you will have to manipulate the string yourself....
firtunately, the field should always be the same size. You can use the php substr method which takes string, offset and lengh as arguments....eg, the first hour would be
Expand|Select|Wrap|Line Numbers
  1.  
  2. $hr1=substr($Date,0,2);
  3.  
the second would be
Expand|Select|Wrap|Line Numbers
  1. $h2=substr($Date8,2);
  2.  
etc...
If you wanted to, you could store them all in an Array - and use a loop to calculate them....
Jul 25 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jim Adams | last post by:
My Access app stamps the date and time for each database entry. I'd like to generate a report of: - the number of entries per hour of day (0 - 23), and also - the number of entries per day of...
2
by: mtech1 | last post by:
Access 2003 I need to create a query to view data by 3 - 24 hour shifts. Ex: There are 3 shifts, each shift is 24 hours starting at 0700 through 0700. Each shift is designated as A, B, or C. ...
3
by: Pieter Coucke | last post by:
Hi, For some reason, somewhere in my application 1 hour is added to my dates, depending in which time zone the application is run... Because I don't have a clue where this happens, I posted this...
5
by: Summu82 | last post by:
HI I have to convert a time in the format i have year month day hour min and seconds I need to convert this into time in seconds since 1 jan 1970 i.e the
3
by: Shawn Yates | last post by:
I have a database that I am using as a Time clock where employees can clock in and out. Is there a way to make it so that when they clock out a form would open displaying their work day hour by...
2
by: =?Utf-8?B?R2ls?= | last post by:
I have a server (Win2k3 SBS) that is a domain controller and exchange server. I failed to apply the DST patches until after the DST kicked in. I have since completed successfully the patches and...
2
by: nex85 | last post by:
hi! HOUR FROM TIME i) does anyone know how to determine which hour a time value lies in? the arrival time is in hh:mm:ss format. for e.g.: for an arrival time of 17:00:26, the correct conversion...
11
by: jonathan184 | last post by:
Hi I am trying to do a script to monitor a dir where files pass through approx every 5 mins but sometimes files may not come in for hours So the purpose of the script is to monitor by if no files...
10
ollyb303
by: ollyb303 | last post by:
Hello, Need some help with an Access 2000 query. My query is based on a table which is a log of calls to my company. I am using a date range entered by the user (Date Between And ) and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.