473,386 Members | 1,699 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,386 software developers and data experts.

Php Problem to get hour & minutes from smalldatetime types

24
Hi all, I am working on a module of Php project with SQL server. I design a date filed in the table smalldatetime types. I want to get Hour and minutes. I write the code bellow: Its works for hour but not for minutes. pls give me idea if diff way ...... many thx
Expand|Select|Wrap|Line Numbers
  1. $S= gmdate("H", strtotime($row[2])); 
  2. $Sm= gmdate("m", strtotime($row[2]));
Jul 23 '08 #1
3 2953
pbmods
5,821 Expert 4TB
Heya, Shaif.

'm' fetches the day of the month with leading zero. You want 'i' (http://php.net/date).

Also, for performance, consider doing something like this so that you only have to call strtotime() once:
Expand|Select|Wrap|Line Numbers
  1. $timeRow = strtotime($row[2]);
  2. $S= gmdate("H", $timeRow);
  3. $Sm= gmdate("m", $timeRow);
  4.  
Jul 23 '08 #2
shaif
24
Heya, Shaif.

'm' fetches the day of the month with leading zero. You want 'i' (http://php.net/date).

Also, for performance, consider doing something like this so that you only have to call strtotime() once:
Expand|Select|Wrap|Line Numbers
  1. $timeRow = strtotime($row[2]);
  2. $S= gmdate("H", $timeRow);
  3. $Sm= gmdate("i", $timeRow);
  4.  

Hi Pbmods, Ya its working how ever , its get only rounded minutes such as 30 mins only if have. But if 00.09 , its cant count. Is there any way to get exact minutes pls?
Jul 23 '08 #3
pbmods
5,821 Expert 4TB
You want to round to the nearest 30 minutes?

Expand|Select|Wrap|Line Numbers
  1. $minutes = ((int) ($minutes / 30 + .5)) * 30;
  2.  
Jul 24 '08 #4

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

Similar topics

4
by: Chris | last post by:
Hi, I have a table in SQLServer2000 where e.g. the actual time is insert for every record (smalldatetime). But how do I select every records newer than 90 minutes? /Chris
0
by: Demetri | last post by:
I have 2 web services. Web service "Main" and a Web Service "Proxy". I also have a shared libary of complex types. The "Proxy" web service simply calles methods of the "Main" web service. When...
2
by: James P. | last post by:
Hello, In my Access report, I have a minutes field in the detail line. How do I convert that minute to hour and minute. The problem for me now is if I take the minutes, say 75 divide by 60, it...
1
by: Demetri | last post by:
I have created a class library which is shared by multiple projects. One project is the web service. It has a web method that when invoked is to return a class populated with all of the properties...
1
by: Paul M. | last post by:
Hello, is there any way of using Hex, Byte & Bit data types in Crystal formula basic? I have an algorithm that uses Hex etc and I would like to use it in a Crystal formula. Cheers Paul
8
by: Alex Vinokur | last post by:
Here is a code from http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8 -------------------------------------- class Shape { public: virtual ~Shape() { } // A...
3
by: kikazaru | last post by:
Is it possible to return covariant types for virtual methods inherited from a base class using virtual inheritance? I've constructed an example below, which has the following structure: Shape...
1
by: hpbrothers | last post by:
How to declare hexa & octadecimals data types in c++
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.