By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

GregorianToJD Help

P: n/a
I have date of birth fields in a table defined as varchar data - year,
month and day - these are defined as varchar data because the user
selects them from a dropdown listbox.

I can't get the Gregorian To juilan date funtion to produce anything
except 0 - it's the 3 arguments: month, day, year - they need to be
integers so I use intval() to convert each one and then feed that into
the Gregorian function but I still get 0 as the results - if I hard
code the 3 arguments in as (10,20,195) then it works - why won't the
integer conversion function work???

$php_SQL = "SELECT * FROM personal";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_row = mysql_fetch_object($php_resultID);
$php_dob_year = $php_row->dob_year;
$php_dob_month = $php_row->dob_month;
$php_dob_day = $php_row->dob_day;

$month = intval($php_dob_month);
$day = intval($php_dob_day);
$year = intval($php_dob_year);
$jd = GregorianToJD ($month,$day,$year);
print "<BR>$jd";

Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ralph Freshour <ra***@primemail.com> wrote:
I have date of birth fields in a table defined as varchar data - year,
month and day - these are defined as varchar data because the user
selects them from a dropdown listbox.

I can't get the Gregorian To juilan date funtion to produce anything
except 0 - it's the 3 arguments: month, day, year - they need to be
integers so I use intval() to convert each one and then feed that into
the Gregorian function but I still get 0 as the results - if I hard
code the 3 arguments in as (10,20,195) then it works - why won't the
integer conversion function work???


Hi Ralph,

First, are you sure the correct values are returned from the SQL query?

Secondly, intval doesn't work with objects. As you assign the value of the
objects to new variables, PHP also automatically changes their type to
objects.

Try explictly converting the values to integer:

$php_SQL = "SELECT * FROM personal";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_row = mysql_fetch_object($php_resultID);
$php_dob_year = $php_row->dob_year;
$php_dob_month = $php_row->dob_month;
$php_dob_day = $php_row->dob_day;

$month = (int)$php_dob_month;
$day = (int)$php_dob_day);
$year = (int)$php_dob_year;
$jd = GregorianToJD ($month,$day,$year);
print "<BR>$jd";

HTH;
JOn

Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.