bashiro's avatar

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

0 likes
5 replies
Tray2's avatar

What is it that you are trying to achieve?

Mega_Aleksandar's avatar
Level 18

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

1 like
Snapey's avatar

perhaps if you explained what $event_countdown_data->start_date looks like?

Is it a string, what format?

a Carbon instance?

bashiro's avatar

Thanks for the reply. It is ordinary date object in the database. The suggestion of Mega_Aleksandar helped solved the issue. Thanks alot

Please or to participate in this conversation.