DateTime not working with1.3.6?

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
287
Points
18
Age
31
Location
Tennessee
Mysidian Dollar
13,377
So I have this seasons code:

$today = new DateTime();
if(new DateTime() < new DateTime($today->format('Y').'-3-20 00:00:00')) $season = "Winter <img src=''>";
else if (new DateTime() < new DateTime($today->format('Y').'-6-21 00:00:00')) $season = "Spring ";
else if (new DateTime() < new DateTime($today->format('Y').'-9-22 00:00:00')) $season = "Summer <img src=''>";
else if (new DateTime() < new DateTime($today->format('Y').'-12-20 00:00:00')) $season = "Fall <img src=''>";
else $season = "Winter <img src=''>";
$this->moneyBar->add(new Comment("<b id='season'>{$season}</b><br>"));

That works for both my sites, and for some reason my friend's 1.3.6 site isn't allowing the code and makes an error across the page. Any idea how I can fix this? It's not accepting the new DateTime() function.
 
For Mys v1.3.6, you need to add this line to the top of the file following the <?php tag:

PHP:
use DateTime;

This is because every file/class in Mys v1.3.6 is namespaced, unlike Mys v1.3.5 and earlier in which only files/classes in the /classes folder have namespace. PHP will not import built-in classes unless you write a use statement, its annoying(most programming languages dont work like this) but we have to deal with it.
 
For Mys v1.3.6, you need to add this line to the top of the file following the <?php tag:

PHP:
use DateTime;

This is because every file/class in Mys v1.3.6 is namespaced, unlike Mys v1.3.5 and earlier in which only files/classes in the /classes folder have namespace. PHP will not import built-in classes unless you write a use statement, its annoying(most programming languages dont work like this) but we have to deal with it.
Thank you so much! This worked :D I only know basic code so I had no idea how to fix that XD
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,113
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top