How to add my local function in other OOP application?

Hi everybody,
I have my own library and function which can convert Gregorian calendar to my own calendar. In general it works without problem.
For example, when I use some code like this, it returns the correct result for me.
`require_once jdf.php;

function convert($date) {
if(($date) == '0000-00-00 00:00:00'){
echo '';
}else{
echo mds_date('Y-m-d H:i:s', strtotime($date), 1);
}
}
$query = '';
$results = mysqli_query($db, $query);
while($row = mysqli_fetch_array($results)) {
echo convert($row['DEL_DELEGATE_DATE'][);
}

But, when I want to use it in another application, it does not work.

I add the convert function like this:

dDelegateDate'   =>  $this -> createDateFromString(convert($row['DEL_DELEGATE_DATE']))

How to add convert function to the OOP file?
Thanks in advance

Your function should return the value it produces, so that you can use the result in any context. By echoing the value inside the function, it is not general-purpose, and you can only use the function in a html context.

1 Like

Thanks for your reply,
So where should I add my function to change the result? I want to be shown the date in html page based on my function.but it returns grogorian calendar yet?

Unless you are doing something I don’t know about, the database table should be storing it in that format if you are using DateTime as the type with CURRENT_TIMESTAMP as the default, plus you can make your own default if you so wish to do so? Though I believe you can’t use DateTime as the type.

1 Like

I am not good with oop, but, you convert the standard Gregorian mysql format to the Persian format using mds_date() format. Then you convert it back to a standard date format using createDateFromString function. I am confused why you would ever want to do that. Normally, you just keep all of your dates standard something like this…

dDelegateDate'   =>  $this -> $row['DEL_DELEGATE_DATE']);

And, then, when it is used to be displayed on a page you would process the conversion function. There is no reason to run all the conversions to store it again and then convert a second time. Just keep the date the same as mysql and when you display it use your conversion process. I am not sure, but, this makes more sense to me.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service