Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2005, 03:52 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default how do i break it up?

I have a field that records the time of record inserts.
I am trying to break up the time inserts into 3 parts for editing.

eg. 1:00 PM --> hr = 1, min = 00, symbol= PM

Is there a way to do it?

Thanks
 
Old January 18th, 2005, 11:31 AM
Authorized User
 
Join Date: Jan 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is this a PHP timestamp, or a SQL field that you are trying to query?

 
Old January 19th, 2005, 12:07 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

its a sql field.
 
Old January 19th, 2005, 09:52 AM
Authorized User
 
Join Date: Jan 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It depends on the DBMS that you are using. MySQL has a lot more built in date/time functions than SQL Server 2000 for example, but do a little research on your system to see what functions there are. This will work with all of the common ones..

If you are using MySQL, you can do it with just a single sql command:

Code:
select date_format(db_column, '%h') as hr, date_format(db_column, '%i') as min, date_format(db_column, '%p') as symbol from table_name
If its not MySQL
SQL statement:
Code:
Select hour(db_column) as hr, minute(db_column) as mn from table
Symbol Logic:
Code:
$symbol = "am";
if ($hr >= 12)
     $symbol = "pm";


Now you have all three parts to work with. Just be sure that it is of type datetime or time. Also note that some other MySQL functions have the ability to return hours > 24 if doing comparisons or other operations. This would change your logic here.

Hope this helps.

Jeff





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why there isn't a "break"? XVenus Java Basics 1 September 4th, 2007 06:37 AM
help with 'break' Manu Sharma Beginning PHP 3 March 15th, 2007 09:04 PM
Page Break Dhawood ASP.NET 2.0 Basics 0 August 8th, 2006 08:02 AM
break up line crmpicco Javascript How-To 1 June 6th, 2005 06:54 AM
Unable to Break at Break point Girishbk VB.NET 2002/2003 Basics 0 January 18th, 2005 08:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.