473,396 Members | 1,866 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.

Swap 2007-03-15 to 15-03-2007

Swap 2007-03-15 to 15-03-2007

Given i have 50,000 dates in a text file to change i'm looking for the
fastest way of doing it .

Mar 16 '07 #1
4 1165
Krustov schreef:
Swap 2007-03-15 to 15-03-2007

Given i have 50,000 dates in a text file to change i'm looking for the
fastest way of doing it .
lotsa ways .. try this one

$pieces=explode($date,'-');
$newdate = $pieces[2].'-'.$pieces[1].'-'.$pieces[0];

or take a look at the mysql date format or use substr() or whatever else
you can think of :-)

--
Arjen
http://www.hondenpage.com
Mar 16 '07 #2
Rik
On Fri, 16 Mar 2007 19:15:31 +0100, Krustov <me@privacy.netwrote:
Swap 2007-03-15 to 15-03-2007

Given i have 50,000 dates in a text file to change i'm looking for the
fastest way of doing it .
Fastest way, if the format is consistent:

$date_array = explode('-',$string);
array_reverse($date_array);
$string = implode('-',$date_array);

But as it is a textfile:

$oldfile = '/path/to/old/file';
$newfile = '/path/to/new/file';
$old = fopen($oldfile,'r');
$new = fopen($newfile,'w');
while($data = fscanf($old,"%s-%s-%s\n")){//change according to format
array_reverse($data);
fwrite($new,implode('-',$data)."\n");
}
--
Rik Wasmus
Mar 16 '07 #3
<comp.lang.php>
<Floortje>
<Fri, 16 Mar 2007 19:24:02 +0100>
<45***********************@news.wanadoo.nl>
$pieces=explode($date,'-');
$newdate = $pieces[2].'-'.$pieces[1].'-'.$pieces[0];
That looks fine and just what i'm after - thanks dude .

Mar 16 '07 #4
<comp.lang.php>
<Rik>
<Fri, 16 Mar 2007 19:31:00 +0100>
<op.tpaodyb7qnv3q9@metallium>
Fastest way, if the format is consistent:

$date_array = explode('-',$string);
array_reverse($date_array);
$string = implode('-',$date_array);
Saved to disk although Floortge's method might be more practical as i
might want to add a extra line of text and only use a part of the date .

Mar 16 '07 #5

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

Similar topics

5
by: Steve Hill | last post by:
Hi, suppose I have a vector allocated on the heap. Can I use a temporary (stack based vector) and swap to clear it, or is this unsafe. e.g. vector<int> *v; vector<int> tmp; v->swap(tmp); // is...
2
by: ma740988 | last post by:
So I'm reading the C++ coding standards(Shutter & Andrei), more specifically item 56. There's a statement: "Prefer to provide a nonmember swap function in the same namespace as your type when...
7
by: Kai-Uwe Bux | last post by:
Hi folks, I am still struggling with the rules for name lookup. Please consider: namespace xxx {
14
by: Otto Meijer | last post by:
Hi everyone, for one of my projects I need to figure out the size of the swap file(s) of a certain system. The problem is I need to do this on a host of platforms like: HP_UX, Solaris, Linux,...
12
by: Eugen J. Sobchenko | last post by:
Hi! I'm writing function which swaps two arbitrary elements of double-linked list. References to the next element of list must be unique or NULL (even during swap procedure), the same condition...
9
by: Jongmin Lee | last post by:
Hi Everybody, I have very simple code snippet to explain my problem. Class "Swap" is construncted in "Main" with two initial variables. Later, "Swap" class is going to swap those two...
4
by: Niels Dekker (no reply address) | last post by:
When calling swap as follows (as recommanded in Effective C++, 3rd Edition, by Scott Meyers), what swap is chosen to be called? using std::swap; swap(a, b); Suppose there is a global ::swap...
9
by: ma740988 | last post by:
Consider: # include <vector> # include <iostream> # include <cstdlib> # include <ctime> bool ispow2i ( double n ) {
3
by: Narmada Padhy | last post by:
1> #include<iostream> using namespace std; void swap(int& i, int& j) { int tmp = i; i = j; j = tmp; cout<<"The value after swap of x and y is"<<i<<" "<<j<<endl;
4
by: George2 | last post by:
Hello everyone, The following swap technique is used to make assignment operator exception safe (means even if there is exception, the current object instance's state is invariant). It used...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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.