Parameters url set syntax date


#1

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

#2

Why are you passing it through the URL?


#3

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.


#4

Use the POST method.


#5

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


#6

How about using a proper date syntax?


#7

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?


#8

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?


#9

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');

#10

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.


#13

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