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

mktime question

I understand that mktime will convert a date to a unix timestamp:

mktime(13, 42, 0, 10, 5, 2004)

but if my dates are this format:

Oct 05 2004 01:42 pm

how do I convert each element to a number? Is there a function for this?
Do I need to use an array? Switch statements?

Thanks in advance.
Jul 17 '05 #1
3 1572
deko wrote:

I understand that mktime will convert a date to a unix timestamp:

mktime(13, 42, 0, 10, 5, 2004)

but if my dates are this format:

Oct 05 2004 01:42 pm

how do I convert each element to a number? Is there a function for this?
Do I need to use an array? Switch statements?


http://ca3.php.net/manual/en/function.strtotime.php
http://www.gnu.org/software/tar/manu..._7.html#SEC110

Not sure if your format conforms to an accepted one or not. If it doesn't,
you'll likely need a preg_replace() with a regex (something like "/^([a-z]+)
(\d{2}) (\d{4}) (\d{2}):(\d{2}) (am|pm)$/i" ) <-- UNTESTED.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #2
> Not sure if your format conforms to an accepted one or not. If it
doesn't,
you'll likely need a preg_replace() with a regex (something like "/^([a-z]+) (\d{2}) (\d{4}) (\d{2}):(\d{2}) (am|pm)$/i" ) <-- UNTESTED.


It seems getting "Oct 05 2004 01:42 pm" into "13, 42, 0, 10, 5, 2004" is the
challenge. I was thinking I could explode each string into an array and
then use a switch statement for translating the month, and add 12 to the
first side of the ":" in the time (another array) if "pm", and then just put
the array back together separated by commas. will have to do some
testing...
Jul 17 '05 #3
deko wrote:
It seems getting "Oct 05 2004 01:42 pm" into "13, 42, 0, 10, 5, 2004" is the
challenge.

$ cat time.php
<?php
$in = "Oct 05 2004 01:42 pm";
$out = strtotime($in);

if ($out == NULL) echo "unable to convert\n";
else {
echo "\"$in\" converts to ",
date('G, i', $out), ", ",
1*date('s', $out), ", ",
date('n, j, Y', $out), "\n";
}
?>

$ php time.php
"Oct 05 2004 01:42 pm" converts to 13, 42, 0, 10, 5, 2004

--
================== My mail address is spam-trapped ==================
To: "My Name" <myaddress> | messages without these three
Content-Type: text/plain | conditions _will_ be sent to
size < 10K | /dev/null
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bengt Richter | last post by:
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 0))...
2
by: Florian Quetting | last post by:
Hi, I'm getting mad with following problem: The code compiles, but I always get a segfault and I don't have any clue why. I can't see any differences in my way of calling mktime and others. ...
16
by: John Hanley | last post by:
I created a function that breaks down a date into broken down time, I subtract a certain number of seconds from that, then use mktime() to recompute the calendar time. It works basically except...
5
by: Robert Latest | last post by:
Here's what happens on my Windows machine (Win XP / Cygwin) at work. I've googled a bit about this problem but only found references to instances where people referred to dates before the Epoch. ...
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: 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:
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
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...
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.