0

Date data saved from stripe start_date as string timestamp like "1652789095". Now I want to filter with this timestamp string form last 12 months. what should I do ? how can I filter with this timestamp string?

3
  • 1
    this looks like a unix timestamp. Some answers here: stackoverflow.com/questions/16609722/… and here: postgresonline.com/article_pfriendly/3.html Commented Jun 18, 2022 at 21:29
  • I would imagine as well that you can subtract 31536000 (the number of seconds in a year) from 1652789095 and that is the number you are looking for as well ( records where start_date is greater than 1621253095) :) Commented Jun 18, 2022 at 21:31
  • Actually date saved in database as string timestamp. Now my goal is filter with this timestamp. Commented Jun 19, 2022 at 4:28

1 Answer 1

0

These are some examples - I'm sure there are plenty of options that would work.

convert to date

select *
from Table
where 
  to_timestamp(cast(start_date as int)::date > date_add(now(), interval -1 year);

work with unix timestamps

-- approx 1 year ago, by way of example
select * 
from Table
where
  start_date > '1621253095';

-- exactly one year ago, calculated dynamically
select * 
from Table 
where 
  start_date > 
    cast(unix_timestamp(date_add(now(), interval -1 year)) as varchar);

I'm not a MySQL guy really so forgive any syntax errors and fix up the sql as needed to work in MySQL.

Resources:

PostgreSQL: how to convert from Unix epoch to date?

https://www.postgresonline.com/article_pfriendly/3.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.