473,398 Members | 2,393 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,398 software developers and data experts.

Combine the date and time

250 100+
In my php application I got the date and time as two separate values.(User entered value)
ex:date =06-07-2008
time =16:10

I want to combine those two values and convert the date format like the following. 2008-07-03 14:08:16

How can I do that. Could you please help me?

This is my code.
[PHP]
$message = $_GET['message'];
$mn=split(" ",$message);
echo "$mn[0]<br>";
echo "$mn[1]<br>";
[/PHP]
Current out put
06-07-2008
16:10
Aug 6 '08 #1
8 7497
r035198x
13,262 8TB
1.) Why are you putting the <br> if you don't want the strings to be split?
2.) You can concatenate strings using the dot (.) operator.
3.) Why did the time part change from 16 ... to 14 ...?
Aug 6 '08 #2
ghjk
250 100+
1.) Why are you putting the <br> if you don't want the strings to be split?
2.) You can concatenate strings using the dot (.) operator.
3.) Why did the time part change from 16 ... to 14 ...?

If I didn't put <br> I got the out put 06-07-200816:10. I want to put a space between date and time. Also date should be 2008-07-06.

My final out put should be 2008-07-06 16:10
Aug 6 '08 #3
r035198x
13,262 8TB
If I didn't put <br> I got the out put 06-07-200816:10. I want to put a space between date and time. Also date should be 2008-07-06.

My final out put should be 2008-07-06 16:10
Browse this list and pick the most appropriate functions to use. Try the code and post again if you still have problems.
Aug 6 '08 #4
pbmods
5,821 Expert 4TB
Heya, ghjk.

What is the value of $_GET['message']? From your code and output, it looks like it's already formatted the way you need...?

Try something like this:
Expand|Select|Wrap|Line Numbers
  1. $date = date('Y-m-d H:i:s', strtotime($_GET['message']));
  2.  
Aug 6 '08 #5
r035198x
13,262 8TB
Heya, ghjk.

What is the value of $_GET['message']? From your code and output, it looks like it's already formatted the way you need...?

Try something like this:
Expand|Select|Wrap|Line Numbers
  1. $date = date('Y-m-d H:i:s', strtotime($_GET['message']));
  2.  
Spoil sport
Aug 6 '08 #6
ghjk
250 100+
I Did That. DT=06-08-2008 15:02
[PHP]
$Da = substr("$DT ", 0, 2);
$Mn = substr("$DT", 3, 2);
$Ye = substr("$DT ", 6, 4);
$Ho = substr("$DT", 10, 2);
$Mi = substr("$DT ", 13, 2);

$Date = $Ye."-".$Mn."-".$Da." ".$Ho.":".$Mi;
[/PHP]
Aug 6 '08 #7
r035198x
13,262 8TB
I Did That. DT=06-08-2008 15:02
[PHP]
$Da = substr("$DT ", 0, 2);
$Mn = substr("$DT", 3, 2);
$Ye = substr("$DT ", 6, 4);
$Ho = substr("$DT", 10, 2);
$Mi = substr("$DT ", 13, 2);

$Date = $Ye."-".$Mn."-".$Da." ".$Ho.":".$Mi;
[/PHP]
Edit : Also check out pb's version.
Aug 6 '08 #8
pbmods
5,821 Expert 4TB
Spoil sport
0 : )
Aug 6 '08 #9

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

Similar topics

9
by: Steve Jorgensen | last post by:
Hi all, I'm working on the schema for a database that must represent data about stock & bond funds over time. My connundrum is that, for any of several dimension fields, including the fund name...
5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
5
by: jhutchings | last post by:
Hello everyone, I have a database where I collect shipment data from various tables. However, I have a problem. Whenever I want to see shipping data for orders that were set to ship on or before...
1
by: rdraider | last post by:
Hi all, We have an app that uses SQL 2000. I am trying to track when a code field (selcode) is changed on an order which then causes a status field (status) to change. I tried a trigger but...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
2
by: drurjen | last post by:
Good morning. I am importing an XLS file into one of my tables. The fields are: Date Id Time IO 12/22/2006 2 12:48:45 PM 9 12/22/2006 16 5:40:55 AM 1 12/22/2006 16 12:03:59 PM 2 ...
14
by: TIonLI | last post by:
I am working with a table that lists dates and corresponding times in separate fields. For purposes of building a query to calculate elapsed time I would like to combine a field with a field ending...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
4
by: ghjk | last post by:
In my php application user should enter date and time separately. But i want to combine them to compare with database value. How can i do that? user input Date:2008-03-25 User input time:11:30 Eg;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.