这是我的代码,我试图根据当前日期对结果进行排序以获取数据。
我需要的是让jb_expiry_date更接近当前日期的日期
SELECT vm_jobs_category.*
, vm_jobs.*
, DATE_FORMAT(vm_jobs.jb_expiry_date,'%Y%m%d') AS pub
, vm_seo_detail.*
, vm_publications.*
FROM vm_jobs
INNER JOIN vm_jobs_category
ON (vm_jobs.jb_jc_id = vm_jobs_category.jc_id )
INNER JOIN vm_seo_detail
ON (vm_jobs.jb_id = vm_seo_detail.sd_ty_id AND vm_seo_detail.sd_ty = 'vm_jobs' )
INNER JOIN vm_publications
ON (vm_jobs.jb_id = vm_publications.ty_id AND vm_publications.ty_name = 'vm_jobs' AND vm_publications.status = '1')
WHERE (vm_jobs.jb_expiry_date != '' AND vm_jobs.jb_expiry_date != '1970-01-01' AND vm_jobs.jb_expiry_date != '0000-00-00')
ORDER BY pub DESC
答案 0 :(得分:0)
只需计算当前日期的差异(以适合您的任何单位)并按此顺序。
...
ORDER BY TIMESTAMPDIFF(DAY, vm_jobs.jb_expiry_date, NOW())