wood burning stoves 2.0*
The moose likes PHP and the fly likes import date from file, then compare with today's date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » PHP
Bookmark "import date from file, then compare with today Watch "import date from file, then compare with today New topic
Author

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

Marjorie Gyles
Ranch Hand

Joined: Nov 03, 2012
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
Sign up for ACM, 3, 02/12/14
Find thesis advisor, 2, 02/25/14
Write thesis intro, 1, 02/25/14
Sign up for "online" course, 3, 01/12/14


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

Joined: Jul 19, 2004
Posts: 5139
    
  12

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."
  • ...


  • SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
    http://www.javaroe.be/
    Marjorie Gyles
    Ranch Hand

    Joined: Nov 03, 2012
    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[]
    read first item from data[0]
    place in the first cell named item
    read second item from data[1]
    place in second cell named priority
    read third item from data[2]
    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
    Bartender

    Joined: Jul 19, 2004
    Posts: 5139
        
      12

    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)
     
     
    subject: import date from file, then compare with today's date
     
    Similar Threads
    problems with two divs sitting next to the other.
    problem in running a servlet
    how to load a page properly ?
    How to process operation on check box here
    Page displaying in IE6 and older versions but not in Higher versions, chrome and firefox also.