What is it that you are trying to achieve?
Countdown
Hello everyone, I am having this issue of replacing the following values in a script var countDownDate = new Date("2025-10-31 15:37:25").getTime(); with laravel values in a blade $event_countdown_data->start_date $event_countdown_data->start_time
Is there any one than can help me replace the date and time above with the laravel values ?
I have tried this var countDownDate = new Date('{{ $event_countdown_data->start_date }} {{ $event_countdown_data->start_time }}').getTime(); without success. Any help is appreciated. Thanks a lot Bashiro
Hello @bashiro ,
From what I can see, your new Date("2025-10-31 15:37:25") is missing a few key components to be compliant with the javascript Date object. You need to write it in a specific way in order to get the vanilla javascript to create the proper object
//2024-11-03 01:30 this is something you can/would get from the database
new Date(2024, 10, 3, 1, 30) // by the docs YYYY-MM-DDTHH:mm:ss.sssZ
// this gives you a proper javascript Date object like Sun Nov 03 2024 01:30:00 GMT-0400 (Eastern Daylight Time)
so, for your example, you need to split the start_date and start_time to its components (either with Carbon or by doing it in javascript:
const dateFromBackend = {{ $event_countdown_data->start_date }};
const timeFromBackend = {{ $event_countdown_data->start_time }};
const date = dateFromBackend.split('-');
const time = timeFromBackend.split(':');
let countDownDate = new Date(date[0], date[1], date[2], time[0], time[1], time[2])
Hope it helps,
Mega Aleksandar
Please or to participate in this conversation.