Why are timestamps returning the month instead of actual time?

Solved

Why are timestamps returning the month instead of actual time?

SergioCosta
Shopify Partner
4 0 1
I've started having this issue recently as this was working properly last week.
 
{% assign today_date = 'now' | date: '%m-%d-%Y' %}
{% assign today_date_ts = today_date | date: '%s' | plus: 0 %}
 
today_date_ts should be the timestamp, which was fine a week ago or so
 
Right now date: '%s' is returning the month of the date, not a timestamp.
 
For 12-15-2022, for example,it returns 12
For 11-15-2022, it returns 11
 
And so on.
 
Any ideas?
Accepted Solution (1)
Litos
Globetrotter
688 169 150

This is an accepted solution.

Hi @SergioCosta,

Please change code:

{% assign i_date = settings.sale_begin_date | date: '%m-%d-%Y' %}

=>

{% assign i_date = settings.sale_begin_date | date: 'format: 'default'' | date: '%s' %}

with the format of the date as 'Y-M-D', for example: '2022-12-16'

Hope it helps!

Litos - Shopify Development Service Provider
Need to develop or customize your Shopify store, feel free to contact us here.

View solution in original post

Replies 7 (7)

Litos
Globetrotter
688 169 150

Hi @SergioCosta,

Please change code:

{% assign today_date_ts = today_date | date: '%s' | plus: 0 %}

=>

{% assign today_date_ts = 'now' | date: '%d' | plus: 0 %}

Hope it helps!

Litos - Shopify Development Service Provider
Need to develop or customize your Shopify store, feel free to contact us here.
SergioCosta
Shopify Partner
4 0 1

Thank you very much for pitching in but that gives me the day of the month for today, not the timestamp.

 

%s should give me the timestamp, yet it's returning the month. And this was working a week ago, which brings me to believe there was a bug induced in Shopify meanwhile.

Litos
Globetrotter
688 169 150

Hi @SergioCosta,

You can try this:

{% assign today_date = 'now' | date: '%s' %}
{% assign today_date_ts = today_date | plus: 0 %}

Hope it helps!

Litos - Shopify Development Service Provider
Need to develop or customize your Shopify store, feel free to contact us here.
SergioCosta
Shopify Partner
4 0 1

Thank you.

 

That direct conversion works with 'now' but not with string dates, unfortunately. I do find it odd that converting to a date and then to timestamp doesn't work though. Any idea why that may be?

 

An example:

 

{% assign i_date = settings.sale_begin_date | date: '%m-%d-%Y' %}
{% assign i_date_ts = i_date | date: '%s' | plus: 0 %}

 

I'm using the first line above to make sure date formatation is recognized.

 

But this doesn't work either. It always returns the month.

 

{% assign i_date_ts = settings.sale_begin_date | date: '%s' | plus: 0 %}

 

Any ideas?

 

Thank you.

Litos
Globetrotter
688 169 150

This is an accepted solution.

Hi @SergioCosta,

Please change code:

{% assign i_date = settings.sale_begin_date | date: '%m-%d-%Y' %}

=>

{% assign i_date = settings.sale_begin_date | date: 'format: 'default'' | date: '%s' %}

with the format of the date as 'Y-M-D', for example: '2022-12-16'

Hope it helps!

Litos - Shopify Development Service Provider
Need to develop or customize your Shopify store, feel free to contact us here.
SergioCosta
Shopify Partner
4 0 1

Thank you, that worked. I guess there is no way of keeping the date as mm-dd-yyyy?

Litos
Globetrotter
688 169 150

Hi @SergioCosta,

It's the default format by Shopify, I'm not sure there is another way to change this.

Hope it helps!

Litos - Shopify Development Service Provider
Need to develop or customize your Shopify store, feel free to contact us here.