GregorianToJD Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    #1

    GregorianToJD Help

    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($ph p_SQL, $php_linkID);
    $php_row = mysql_fetch_obj ect($php_result ID);
    $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,$y ear);
    print "<BR>$jd";

  • Jon Kraft

    #2
    Re: GregorianToJD Help

    Ralph Freshour <ralph@primemai l.com> wrote:
    [color=blue]
    > 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???[/color]

    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($ph p_SQL, $php_linkID);
    $php_row = mysql_fetch_obj ect($php_result ID);
    $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_m onth;
    $day = (int)$php_dob_d ay);
    $year = (int)$php_dob_y ear;
    $jd = GregorianToJD ($month,$day,$y ear);
    print "<BR>$jd";

    HTH;
    JOn

    Comment

    Working...