Question
Date Formatting
I need some help formatting some dates. They're extremely
hard for me to
get my head around, for some reason.
I am currently working on this page:
http://demo.mediachurch.com/calendarlist.php (above the hr)
What I am trying to do is capture today's date and compare it with my stored
date in my calendar. The stored date in the calendar is a Serial Date + a
constant. So I need to capture the time, change it to a Serial date, and
then add my constant to compare it to the database.
However, at the moment I'm having a hard time just capturing and formatting
today's date, as you can see. In fact, I'm having a hard time just getting
my formatting script to work as it keep spitting out the same date.
*However* the frustrating part is that my script works to pull out and
format the dates from the calendar (see below the <hr>
.
Here's what I have:
MY TWO RECORDSETS (I can duplicate if you need them)
MY FUNCTIONS AND VARIABLE DEFINITIONS
//VARIABLES
//Get Today's Date
$priivaDateToday = time();
$priivaTestDate = $row_RECORDSETSTUFF
define('EPOCHINEXCEL', 25568); //01-01-1970 minus 1 Defines the serial
date of 1970, which should ensure the script works on windows machines
//This changes the date from MS (days since 1900) to Unix (seconds since
1970)
function priivaExcel2Unix($n) {
return mktime(0, 0, 0, 1, $n - EPOCHINEXCEL, 1970);
}
//This changes the date from Unix to Excel
function priivaUnix2Excel ($n) {
return mktime (0, 0, 0, 1, $n + EPOCHINEXCEL, 1970);
}
THE CODE TO DISPLAY IT ALL
echo "<p> Today's Date: $priivaDateToday </p>";
echo "<p> Today's Date Unix 2 Excel: ";
echo date('l, M jS', priivaUnix2Excel($priivaDateToday));
echo "</p>";
$priivaDateToday = time();
echo "<p> Today's Date $priivaDateToday </p>";
echo "<p> Today's Date Excel 2 Unix: ";
echo date('l, M jS', priivaExcel2Unix($priivaDateToday));
echo "</p>";
echo "<p> First Recordset: $priivaTestDate </p>";
echo "<p> First recordset, formatted: ";
echo date('l, M jS', priivaExcel2Unix($priivaTestDate));
echo "<br />wtf?</p>";
echo "<hr>";
Now, just to clarify a little bit, this is what's on the rest of the page
(ie, the stuff below the HR that is formatting correctly). I have left out a
few functions and variable definitions as it would archive my database
structure and leave obvious security holes.:
//here we write out the head statement if the date is different
if ($priivaDateSame == 0){
?>
<dt><?php echo date('l, M jS', priivaExcel2Unix($priivaDateAdjusted)); ?>
/ <?php echo $priivaEventDate ?></dt>
<dd><?php echo $priivaEventTitle; ?></dd>
<?php
//If it is the same date, don't repeat the header
}
else if ($priivaDateSame == 1) {
?>
<dd><?php echo $priivaEventTitle; ?></dd>
<?php
//this is the completion of the If statement to check dates
}
//This is a completion of the While loop going through the recordsets
}
while ($RECORDSETSTUFF = mysql_fetch_assoc($RECORDSETSTUFF));
echo "</dl>";
//clears the recordset so it can be re-used.
mysql_free_result($RECORDSETSTUFF);
mysql_free_result($rsDateTest);
?>
--
TIA,
Jon Parkhurst
get my head around, for some reason.
I am currently working on this page:
http://demo.mediachurch.com/calendarlist.php (above the hr)
What I am trying to do is capture today's date and compare it with my stored
date in my calendar. The stored date in the calendar is a Serial Date + a
constant. So I need to capture the time, change it to a Serial date, and
then add my constant to compare it to the database.
However, at the moment I'm having a hard time just capturing and formatting
today's date, as you can see. In fact, I'm having a hard time just getting
my formatting script to work as it keep spitting out the same date.
*However* the frustrating part is that my script works to pull out and
format the dates from the calendar (see below the <hr>
Here's what I have:
MY TWO RECORDSETS (I can duplicate if you need them)
MY FUNCTIONS AND VARIABLE DEFINITIONS
//VARIABLES
//Get Today's Date
$priivaDateToday = time();
$priivaTestDate = $row_RECORDSETSTUFF
define('EPOCHINEXCEL', 25568); //01-01-1970 minus 1 Defines the serial
date of 1970, which should ensure the script works on windows machines
//This changes the date from MS (days since 1900) to Unix (seconds since
1970)
function priivaExcel2Unix($n) {
return mktime(0, 0, 0, 1, $n - EPOCHINEXCEL, 1970);
}
//This changes the date from Unix to Excel
function priivaUnix2Excel ($n) {
return mktime (0, 0, 0, 1, $n + EPOCHINEXCEL, 1970);
}
THE CODE TO DISPLAY IT ALL
echo "<p> Today's Date: $priivaDateToday </p>";
echo "<p> Today's Date Unix 2 Excel: ";
echo date('l, M jS', priivaUnix2Excel($priivaDateToday));
echo "</p>";
$priivaDateToday = time();
echo "<p> Today's Date $priivaDateToday </p>";
echo "<p> Today's Date Excel 2 Unix: ";
echo date('l, M jS', priivaExcel2Unix($priivaDateToday));
echo "</p>";
echo "<p> First Recordset: $priivaTestDate </p>";
echo "<p> First recordset, formatted: ";
echo date('l, M jS', priivaExcel2Unix($priivaTestDate));
echo "<br />wtf?</p>";
echo "<hr>";
Now, just to clarify a little bit, this is what's on the rest of the page
(ie, the stuff below the HR that is formatting correctly). I have left out a
few functions and variable definitions as it would archive my database
structure and leave obvious security holes.:
//here we write out the head statement if the date is different
if ($priivaDateSame == 0){
?>
<dt><?php echo date('l, M jS', priivaExcel2Unix($priivaDateAdjusted)); ?>
/ <?php echo $priivaEventDate ?></dt>
<dd><?php echo $priivaEventTitle; ?></dd>
<?php
//If it is the same date, don't repeat the header
}
else if ($priivaDateSame == 1) {
?>
<dd><?php echo $priivaEventTitle; ?></dd>
<?php
//this is the completion of the If statement to check dates
}
//This is a completion of the While loop going through the recordsets
}
while ($RECORDSETSTUFF = mysql_fetch_assoc($RECORDSETSTUFF));
echo "</dl>";
//clears the recordset so it can be re-used.
mysql_free_result($RECORDSETSTUFF);
mysql_free_result($rsDateTest);
?>
--
TIA,
Jon Parkhurst