如何解决根据日期名称获取一年的所有日期
我想根据日期名称选择一年中的所有日期。例如,如果我通过了import React,{ useState,useEffect} from 'react';
import SearchForm from './componenets/Form.js';
import JobLists from './componenets/JobLists'
import axios from 'axios'
function App() {
const [posts,setPosts] = useState([]) //posts store a list of jobs
const [description,setDescription] = useState('') //description of the job (user's input)
const [location,setLocation] = useState('') //location of the job (user's input)
//description input handle
const handleDescriptionChange = (e) => {
setDescription(e.target.value);
}
//location input handle
const handleLocationChange = (e) => {
setLocation(e.target.value);
}
//submit button handle
const onSubmit = e => {
e.preventDefault();
//once the user enter input and clicks on button,update the the useEffect hooks
}
//get data from github job API (fetching by description and location)
const url = `https://cors-anywhere.herokuapp.com/https://jobs.github.com/positions.json?description=${description}&location=${location}`
useEffect(() => {
axios.get(url)
.then(res =>{
console.log(res)
setPosts(res.data)
})
.catch(err =>{
console.log(err)
})
},[])
return (
<div>
<SearchForm
description={description}
handleDescriptionChange={handleDescriptionChange}
location={location}
handleLocationChange={handleLocationChange}
onSubmit={onSubmit} />
{
posts.map((job) => <JobLists job={job} key={job.id} />) //map through each job
}
</div>
)
}
export default App;
。我需要Thu/Thursday and 2020 (Year)
。 我可能发送了一个或多个日期名称,例如,我可能发送了get all the Dates which are coming under Thursday on 2020
。我找不到任何答案。
解决方法
我将使用递归CTE生成所有日期,然后过滤所需的日期:
with dates as (
select datefromparts(2020,1,1) as dte
union all
select dateadd(day,dte)
from dates
where dte < datefromparts(2020,12,31)
)
select d.*
from dates d
where datename(weekday,dte) = 'Thursday'
option (maxrecursion 0);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。