How to convert time in string to time from Ionic to PHP with Mysql?

Asked

Viewed 310 times

0

Good morning guys, I am passing to the server a string that would be for time: 23:45 is an example.

In my $_GET I’m trying to convert this way:

$prazo_entrega_min = time("hh:mm", strtotime($_GET['prazo_entrega_min']));

But without success. What can I do?

I am using in my controller to get this date the plugin ionicTimePicker (https://github.com/rajeshwarpatlolla/ionic-timepicker):

// TEMPO ENTREGA MINIMO
        var ipObj1 = {
            callback: function (val) { //Mandatory
                if (typeof (val) === 'undefined') {
                    console.log('Time not selected');
                } else {
                    var selectedTime = new Date(val * 1000);
                    console.log(selectedTime.getUTCHours(), 'H :', selectedTime.getUTCMinutes(), 'M');

                    $scope.entrega_min = selectedTime.getUTCHours() + ':' + selectedTime.getUTCMinutes();

                    window.localStorage.setItem("prazo_min_entrega", $scope.entrega_min)

                    console.log($scope.entrega_min);
                }
            },
            inputTime: 50400, //Optional
            format: 24, //Optional
            step: 15, //Optional
            setLabel: 'OK' //Optional
        };

        $scope.openTimePicker = function () {
            ionicTimePicker.openTimePicker(ipObj1);
        };

I am storing in my localstorage the values just to check, they are all in string:

inserir a descrição da imagem aqui

What I do wrong?

1 answer

1


You are using the wrong function:

$prazo_entrega_min = time("hh:mm", strtotime($_GET['prazo_entrega_min']));

time() does not accept arguments, always brings the local UTC time. The syntax you used looks more like that of date() (that would actually be H:i for hour:minutes), but return a formatted date.

If the value of your $_GET is the string 23:45 and you need to turn into a timestamp, use

$prazo_entrega_min = strtotime( $_GET['prazo_entrega_min'] );

strtotime() alone already does what you need.

  • With strtotime() only, 14:00 it stores as 838:59:59

  • @branches your code must be modifying the variable prazo_entrega_min after that. See here the original function values: https://eval.in/746598

Browser other questions tagged

You are not signed in. Login or sign up in order to post.