DateTime issue

DateTime issue

by Monika Gujar -
Number of replies: 2

Hello big grin,

My issue is, if I am selecting start time from the dropdown as 10:15 am and end time as 1:05 pm. Then system is considering that, 10 is greater than 1. What should I do? My activity plugin is based on time only.

Below is the code:

mod_form.php

//start date time

$mform->addElement('date_time_selector', 'startdt', get_string('sdat','tgwhiteboard'));

$mform->setDefault('startdt',  $tgwhiteboard->tg_start_datetime);

$mform->addRule('startdt', null, 'required', null, 'client');

//enddate time

$mform->addElement('date_time_selector', 'enddt', get_string('edat','tgwhiteboard'));

$mform->setDefault('enddt',  $tgwhiteboard->tg_end_datetime);

$mform->addRule('enddt', null, 'required', null, 'client');

view.php

//getting all the details from db (stored in variable named, $livesessiondetails)

//1561549800 -- like this

$session_start = date('Y-m-d h:i', $livesessiondetails->tg_start_datetime);

$session_end = date('Y-m-d h:i', $livesessiondetails->tg_end_datetime);

//to start the session before 15 minutes

$start_time = strtotime($session_start);

$start_time = $start_time - (15 * 60);

$start_time = date("Y-m-d h:i", $start_time);

//to add extra 15 minutes into the session

$end_time = strtotime($session_end);

$end_time = $end_time + (15 * 60);

$end_time = date("Y-m-d h:i", $end_time);

Average of ratings: -
In reply to Monika Gujar

Re: DateTime issue

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
You need to turn the times into a unix time stamp for such a comparison.
Either that, or you need to add 12 hours for a PM time, which effectively turns it into a 24-hour clock.
Average of ratings: Useful (2)
In reply to Andrew Lyons

Re: DateTime issue

by Monika Gujar -
thanks... Changed h to H, in datetime format. It worked for me
Average of ratings: Useful (1)