Jump to content

Custom Calander help/question


Demont

Recommended Posts

I have an RPG I've started programming, a MUD.

 

My question, is how would I go about adding into the database, the age of the user's character based on my custom calendar system I have.

 

Here is the code I have for the custom date.

 

<?php
$RealTimeDiff = date("U") - date("U",strtotime("Jan 01, 2008"));
$GameTimeDiff = $RealTimeDiff * 4;
$GameDate = strtotime("Jan 01, 1980") + $GameTimeDiff;
$GameMonth = date("F", $GameDate);
$GameYear =abs(date("Y", $GameDate) - 1980 - 450);
$BirthYear =abs(date("Y", $GameDate) - 1980 - 433);
$Age = $GameYear - $BirthYear;
?>

 

With that, to display the date, I merely have to include the date.php, and print $GameMonth, $GameYear B.C. (as my game is based on The Roman Empire in 450 B.C.)

 

I have, as you can see, the calculation to determine the age, based on the year, but I don't think it would work for every individual who would sign up, as the age would simply calculate the years, based on the current year, and not when that person actually registered.

 

I figured, adding a timestamp of when the person registered, and include the same basic calculation would work, but I'm not sure how to do it. I had someone help me with this simple calculation, as my math skills are atrocious. Any help would be appreciated, and if it helps, here is the code I was going to use for the registration date.

 

$c_hour = date("H");    //Current Hour 
$c_min = date("i");    //Current Minute 
$c_sec = date("s");    //Current Second 
$c_mon = date("m");    //Current Month 
$c_day = date("d");    //Current Day 
$c_year = date("Y");    //Current Year 
$c_timestamp = mktime($c_hour,$c_min,$c_sec,$c_mon,$c_day,$c_year); 

...
...

$insert = "INSERT INTO users (username,charname,regdate,etc...)
VALUES ('".$_POST['username']."','".$_POST['fname']." ".$_POST['lname']."','$c_timestamp')";
$add_member = mysql_query($insert);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.