473,788 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Splitting date into chunks

I'm sure this is an easy one, but I can't seem to find it! I have the
date and time as:

# Nov 28, 2007, 11:11:14pm
$timestamp = 20071128231114;

In Perl, I would split this up as:

my ($year, $month, $day, $hr, $min, $sec) = $timestamp =~ /(\d{4})(\d
\d)(\d\d)(\d\d) (\d\d)(\d\d)/;

How do I do the same thing in PHP? I know that I can use substr, of
course, but there has to be a better way that I'm overlooking.

TIA,

Jason
Nov 29 '07
11 1810
If I type in:
$timestamp = 20050714010317;
echo date('Y m d H i s', $timestamp);
Then it returns:
2038 01 18 22 13 44

---

Then

$timestamp = 20050714010317;
$date = date('Y m d H i s', $timestamp);

$splitted_date = explode(' ',$date); // This is now an array
containing all the date parts.
echo $splitted_date[0]; // Prints the Year part of the date.
Nov 29 '07 #11
On Nov 28, 10:13 pm, Jason Carlton <jwcarl...@gmai l.comwrote:
I'm sure this is an easy one, but I can't seem to find it! I have the
date and time as:

# Nov 28, 2007, 11:11:14pm
$timestamp = 20071128231114;

In Perl, I would split this up as:

my ($year, $month, $day, $hr, $min, $sec) = $timestamp =~ /(\d{4})(\d
\d)(\d\d)(\d\d) (\d\d)(\d\d)/;

How do I do the same thing in PHP? I know that I can use substr, of
course, but there has to be a better way that I'm overlooking.

TIA,

Jason
I'm a bit slow, but I'd accomplish it thusly:

$datetime = 20071128231114;
list($year, $month, $date, $hour, $minute, $second) =
sscanf($datetim e,'%4s%2s%2s%2s %2s%2s');
Nov 29 '07 #12

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

Similar topics

3
2079
by: somaBoy MX | last post by:
I'm building a site where I need to pull very large blocks from a database. I would like to make navigation a little more user friendly by splitting text in pages which can then be navigated. I know how to split a string in chunks, but I need to find a method to make sure the text isn't split in the middle of a word. Any ideas? Thanks,
6
1774
by: Stuart Gilbert | last post by:
I'm trying to split a string on every 2 numbers. I presumed the following would be fine, but I get nothing. var re = /{8}/; var regex = new RegExp(re); if(date.match(regex)) { var dateArray = new Array(4); dateArray = date.split(/{2}/);
6
2286
by: nwheavyw8 | last post by:
I am currently trying to write a simple PHP script that will split an uploading file up into 500kb "chunks", then read and concatenate them back together when accessed for download. I can't seem to be able to find a way to split the file purely in PHP while it is in the middle of uploading using the move_uploaded_file function. I am trying to get it to store the file like so: MySong.mp3 3mb gets uploaded to my server in this...
1
1743
by: Andy Britcliffe | last post by:
Hi I'm faced with the situation where I could have a single physical file that could contain multiplie XML documents e.g file.txt contains the following: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE doc SYSTEM "1.0b.dtd"> <doc transmission-date="20050715T154340Z" >
3
1589
by: La di da Limey | last post by:
Hi, I have a field in a database called "Timestamp" which has the date and time of an event, for example: "01/02/2002 09:07:59" The format is MM/DD/YYYY HH:MM:SS I want to chop the field into six seperate fields of MM, DD, YYYY, HH, MM &
5
3153
by: hecuba007 | last post by:
My apologies if this question has been asked before .. I would like to split large files into smaller chunks for uploading to php for re-assembly on the server. Is there a (relatively) simple way of doing this in javascript? If so, could someone point me to relevant documentation to read or (if really simple!) give me some coding hints? Thanks.
3
2016
by: salad | last post by:
I have an A97 application that is NOT split on a network. It is used by 15+ folks continually. It is quick and fast. I split it several years ago and had to merge it together again after the folks rebelled at the slow speed resulting from the split. I have to bite the bullet and split it now. Of course, it is much slower. In one form that opens as a continous form, the data looks like it is being repainted as it displays...you can...
4
2825
by: yogi_bear_79 | last post by:
I have a simple string (i.e. February 27, 2008) that I need to split into three parts. The month, day, and year. Splitting into a string array would work, and I could convert day and years to integers later. I've bene looking around, and everything I see seems more complicated than it should be! Help!
2
1351
by: David Jackson | last post by:
Hello, The company I'm working for has taken over a smaller company with a fairly large customer base. We want to send an email to that customer base informing them of the takeover but the mailing list is not held in a database. In fact we've been given it as a Word document. The individual email addresses are in the format: "Name <address>" e.g. Bill Gates <billg@microsoft.com>;
0
9498
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
10373
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
10177
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...
1
10118
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7519
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
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
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
3677
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.