Parameters url set syntax date

I need to pass parameters through url and the syntax for the date is 20190121_000.
How do I set the syntax in PHP?

My code:

Arrival Departure

Why are you passing it through the URL?

I am setting up a booking form on the front page, so visitors can start the booking process and be sent to the booking page.

Use the POST method.

Ok, I will use the post method. But how can I set the syntax (20190121_000) for the date?

How about using a proper date syntax?

You can always reformat a string by its parts. However, is there a reason you are not using a normal date format? I have a third party that I am integrating with the requires YYYYMMDDmmssii format, but that is due to their system it needs to be done. It sounds like you are building this, so why create a deviation?

I am going to use this code for parameter booking.

This is the instruction I got:
Parameters that can be called from the home page:
arrival = arrival date
Syntax: 20090909_0000

How do I reformat the string?

If you are not going to validate the date, just split the string into the parts and join them back how you want.

$post = "21/01/2019";
$dateParts = explode('/', $post);
$dateFormat = "{$dateParts['2']}{$dateParts['1']}{$dateParts['0']}_000";

Or

$date = DateTime::createFromFormat('d/m/Y', $post);
echo $date->format('Ymd_000');

Hello Eva,

You may use

$newDateString = date_format(date_create_from_format('d-m-Y', $dateString), 'Ymd_000');

You are first giving it the format $dateString is in. Then you are telling it the format you want $newDateString to be in.

Where does the url become important? Is it something you need, or something that you need to call?

Sponsor our Newsletter | Privacy Policy | Terms of Service