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

if a number is say xx how to make it 20xx, but ignore if it is xxxx?

Ok, I am almost finished with what I was trying to accomplish (pulling
future events from a csv file where the first field is the date). I was
concerned that though I wanted dates entered as mm-dd-yyyy, people often
drop the leading zeros and enter yy. I think I have figured out a way to
cover the leading zeros using sprintf. The problem is now converting
something like 04 to 2004.

This is what I have so far:

<?

$readfile = file("events.txt");

for ($k=0; $k<=count($readfile)-1; $k++) {
$field = split(";",$readfile[$k]);

$date = date("Ymd");

$piece = explode("-", $field[0]);
$day = sprintf("%02d", $piece[1]);
$month = sprintf("%02d", $piece[0]);
$array = array($piece[2], $month, $day);
$c = implode("", $array);
if ($c >= $date) {

print ("$month/$day/$piece[2] $field[1] $field[2], etc.<br>");

}
}

?>

Any thoughts would be appreciated.

Bill
Jul 17 '05 #1
1 1788
The Biscuit Eater <Bo*****************@comcast.net> wrote:
Ok, I am almost finished with what I was trying to accomplish (pulling
future events from a csv file where the first field is the date). I was
concerned that though I wanted dates entered as mm-dd-yyyy, people often
drop the leading zeros and enter yy. I think I have figured out a way to
cover the leading zeros using sprintf. The problem is now converting
something like 04 to 2004.

This is what I have so far:

<?

$readfile = file("events.txt");

for ($k=0; $k<=count($readfile)-1; $k++) {
$field = split(";",$readfile[$k]);

$date = date("Ymd");

$c = date("Ymd", strtotime($field[0]));
if ($c >= $date) {


Hi Bill,

Much easier - use strtotime(). See above.

HTH;
JOn
Jul 17 '05 #2

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

Similar topics

2
by: Henke | last post by:
Hi! Are there any built in classes (or methods) in the framework that can encrypt to some simple string like the one you enter when registring an Microsoft application (xxxx-xxx-xxxx-xxxx)? I...
2
by: Terry | last post by:
Hi, I am new the Javascript. I was wondering if there is a pre-built or pre-written script that can do simple number formatting. When I do a calculation of 2 floating point numbers, I always...
0
by: Brian Davis | last post by:
The problem is in the word boundary \b. A leading "(" will match as a word boundary before it gets to the test for a "(". Changing the expression to: (?n)(\b|\()1??\(?(?<areaCode>\d\d)?\)??(?...
0
by: Darren | last post by:
Hello, I am trying to design an ASP system which will submit the contents of a feedback form to a partner, based on a daily maximum number of feedback forms per day. For example, if...
10
by: Praveen.Kumar.SP | last post by:
Hi Could anyone solve the problem for the code below The Code: #include "stdio.h" #include "iostream.h" void Temp( int a, char* str,...)
2
by: Bruce | last post by:
I have the following line in my assembly.cpp. ; The * allows the build number to be automatically included. Is there any way to reset this build number? If so, how? -- Bruce E....
5
by: Jassim Rahma | last post by:
my CPU mac address is BFEBFBFF000006F6 and my software name is : shefa is there any function or encryption way in C# to generate a 24 digits (alpha numeric) from both CPu MAC address and...
1
by: thaond | last post by:
Hi ! I want to create a Random number be in the Around, but not same the numbers created before ! Exam : My around : 0000,......,9999 Random number was created : 1234, 2134, 0001, 9998...
0
by: PiErre | last post by:
Hi, I have to run a python script on a Linux machine. This script was developed on a windows workstation and it uses the win32 library to detect the cd (or dvd) serial number (in the XXXX-XXXX...
1
by: suresh_nsnguys | last post by:
Respected sir/madam, In My Application, users can send me an email with some keyword 'XXXX' to our mail server 'XXXX@xxxxx.com'.i am using imap_open() and other imap functions to read that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...

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.