473,806 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to tale only hour from the date time

250 Contributor
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:00 13:30:0016:20:0 016:20:00(This include hour:minutes:se conds)
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 9451
Brosert
57 New Member
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 Contributor
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 New Member
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
3956
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 month (1 - 31) Any insights are greatly appreciated. Thanks,
2
2946
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. 01/01/2006 is an "A" shift. The data does have a date field that contains both date and time. Could anyone point me in the right direction to get started?
3
1820
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 to the three relevant newsgroups (vb/ado, sql and xml): my aplogize for this. I'm doing a Synchronisation between two SQL Servers (2000): All the Data is read into a DataSet, and exported to an XML-file: SQL Server -> DataSet (VB.NET 2003) ->...
5
2910
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
2187
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 hour with combo boxes next to each hour that they could select what task they did for the coorisponding hour. For example: lets say the clock in field says "7/5/2006 11:00:00 AM" and the clock out field is "7/5/2006 8:00:00 PM." Once they clock out...
2
2953
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 the time on the server is correct. However this seems to have caused problems on the client PC's(XP Pro SP2). All of the client PC's that have the KB931866 patch installed are now 1 hour AHEAD!!! When I UNCHECK the "Automatically Adjust for DST"...
2
1758
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 should be: 17:00. DAY OF THE WEEK FROM DATE IN VBA ii) if a cell's value is a date, in the form: 14/08/2006, how would you detect which day of the week is it? like monday, tuesday, wednesday, etc. APPEND DATE AND DATE STRING iii) is it...
11
3029
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 pass through in 1 hour send an email. So was thinking to use the shell command to grab the time when a file comes in and write to a txtfile. Now when the files keep coming it will overwrite the old time. Now if no new files are coming in an hour...
10
5041
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 CountOfRefNumber (RefNumber is the PK). Currently I am using this: LogTimes: Format(TimeSerial(Hour(),0,0),"Short Time") & "-" & Format(TimeSerial(Hour(),59,0),"Short Time")
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10110
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.