What are your current thoughts on how you might solve this? What have you already tried? Should we assume this is in JavaScript? Have you looked at the JavaScript language reference for the Date() object? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
#check date range
8 messages · Page 1 of 1 (latest)
this is in js
import { useState, useEffect } from "react";
import useGlobalContext from "../Context/context";
export default function CheckDate() {
const { horoscopeData, setIsFalls } = useGlobalContext();
const [date, setDate] = useState(new Date(horoscopeData.current_date));
const dateRange = "Jan 20 - Feb 18";
const [startStr, endStr] = dateRange.split(" - ");
const startMonth = new Date(startStr).getMonth();
const endMonth = new Date(endStr).getMonth();
const startDate = new Date(startStr).getDate();
const endDate = new Date(endStr).getDate();
const currentMonth = date.getMonth();
const currentDate = date.getDate();
const isWithinRange =
(currentMonth > startMonth ||
(currentMonth === startMonth && currentDate >= startDate)) &&
(currentMonth < endMonth ||
(currentMonth === endMonth && currentDate <= endDate));
console.log(isWithinRange)
useEffect(() => {
if (isWithinRange) {
setIsFalls(true);
}else {
setIsFalls(false)
}
}, [isWithinRange]);
}
i did this but it is showing true all the time
its working now, thank you so much
i have an question, thought.
can i ask that its on TS
i though its working but its not😭