# import date from file, then compare with today's date

Marjorie Gyles
Ranch Hand
Posts: 42
I'm trying to import information from a data.txt file. Every third bit of information is a date. I need to compare that date with the current date, then either bold the information if the date is past, or bold it if the date is today's date. Here's what I've been trying to use, but I'm just getting the white screen.

And here is my data.txt file exactly as it appears in the file.

Pay for classes, 3, 01/06/14
Purchase Books, 1, 01/02/14
Purchase groceries, 1, 01/24/14
Write thesis intro, 1, 02/25/14

This is homework, but I can pull in any sources I want. Any help is appreciated. Thanks in advance.

Roel De Nijs
Sheriff
Posts: 10591
140
Can you explain using pseudo-code (or with short sentences) how you would solve this problem? You always start with thinking about the problem and how it could be solved, before you start coding.

For example:
• Get today's date
• Open file (on failure, print "File could not be read."
• ...
•
Marjorie Gyles
Ranch Hand
Posts: 42
Roel De Nijs wrote:Can you explain using pseudo-code (or with short sentences) how you would solve this problem? You always start with thinking about the problem and how it could be solved, before you start coding.

For example:
• Get today's date
• Open file (on failure, print "File could not be read."
• ...

• I've got all that. The only thing I don't know how to do is to compare the dates from the file with today's date. I have done the algorithm, but have no clue how to go about doing it. Any ideas?

in new div begin table
open file data.txt into data[]
place in the first cell named item
place in second cell named priority
place in third cell named date
compare item data[2] to today's date
if data[2] is past, underline data[0], data[1], data[2]
if data[2] is today, bold data[0], data[1], data[2]
otherwise, echo data[0], data[1], data[2]
continue until all table is filled and eof is reached
in another div echo "Welcome Back!" in <h3>
beneath that echo today's date with day of week
in a third div echo Key in <h3> tag
beneath that list keys to priorities: 1 high, 2 low, 3 medium
end of program

Roel De Nijs
Sheriff
Posts: 10591
140
That looks ok! One remark though: you have place in the first cell named item, place in second cell named priority , place in third cell named date and echo data[0], data[1], data[2]. So it seems you'll be printing the values twice. Or maybe I have misunderstood.

Marjorie Gyles wrote:The only thing I don't know how to do is to compare the dates from the file with today's date. I have done the algorithm, but have no clue how to go about doing it. Any ideas?

Let's start with the easy part. Reading each line of the comma-separated file and just printing the values in the table. When you have this code finished (and working), we can proceed with the next part of the assignment: comparing dates.

This code (from the PHP manual of the fgetcsv method) will be a very good starting point (as you already have done). Just a few pointers:
• absolutely no problem in copying some code from the internet, but always be careful (not all code snippets are of the same quality)
• don't just copy, always know (and understand) what you are copying

• Good luck!

(If you post the working code to print the file content in the table, just limit the code to the actual snippet, not the whole php file)