I know how to code in PHP but admittedly new to Javascript. I am trying to create a link upon collecting the date. When I echo the date from the JS code, it works but adding it inside a link is somehow proving challenging.
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
$date = '<script type="text/javascript">
var event = new Date();
var options = { year: "numeric", month: "numeric", day: "numeric" };
document.write(event.toLocaleDateString("es-CL", options));
</script>';
echo $date; // 18-11-2021
//Unable to create a link
echo '<a href="/example/'.$date.'"> Today </a>';
?>
Unsure what my code is missing. Thanks