search
HomeBackend DevelopmentPHP Tutorial关于php-mysql中按日期排序的有关问题

关于php-mysql中按日期排序的问题!
我在向数据库中插入日期字段time的时候用了strtotime,这样在数据库中显示的数据是这种形式的:1350489600。
然后我在order by time desc的时候发现了这样的问题:2000年02月07日竟然排在了2012年10月19日的前面,这是怎么回事呢?求大侠指教,我想让2012年10月19日排在第一位的。这两个日期的time值分别是949852800和1350576000。

------解决方案--------------------
估计,结果应该是一个字符串,而不是整数。
建议,使用time()直接获取一个时间戳。
------解决方案--------------------
949852800 2000年02月07日
1350576000 2012年10月19日

如果 time 数 int 类型 order by time desc 时必然是后者排在前边
------解决方案--------------------
因为你的 time 字段是 varchar 类型的,改成 int 型就好了。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
time包的单调时钟处理time包的单调时钟处理Aug 04, 2023 pm 05:45 PM

我们今天主要是来看一看golang time 包的时间应用方式。两者的一般规则是「wall time」用于告知时间,而「monotonic clock」用于测量时间;除外还有其他的时钟处理方式。

Java8 Time Api如何使用Java8 Time Api如何使用Apr 28, 2023 pm 12:25 PM

1.概述作为本文的一部分,让我们从现有Date和CalendarAPI存在的一些问题入手,来探讨新的Java8Date和TimeAPI如何解决这些问题。我们还将搞一搞Java8时间类库中的核心类,比如LocalDate,LocalTime,LocalDateTime,ZonedDateTime,Period,Duration以及它们的api。2.旧的时间API(java8之前)的问题线程安全-Date和Calendar类不是线程安全的,使开发者难以调试这些api的并发问题,需要编写额外的代码来处

Python time模块时间怎么获取和转换Python time模块时间怎么获取和转换May 13, 2023 pm 12:19 PM

Pythontime模块时间获取和转换Python的Time库可以进行时间相关的处理,如访问当前日期和时间,输出不同格式的时间以及等待指定的时间等。1.获取时间1.1.时间戳importtimetimestamp=time.time()#1682737552.5009851格林威治时间(GMT)1970年01月01日00时00分00秒起至现在的总秒数1.2.结构化时间importtimestruct_time=time.localtime()#time.struct_time(tm_year=2

python中time和datetime的区别及用法是什么python中time和datetime的区别及用法是什么May 02, 2023 am 11:01 AM

一.Python中表示时间的两种方式:时间戳:相对于1970.1.100:00:00以秒计算的偏移量,唯一的时间元组struct_time:共有9个元素>tm_year:年1-12>tm_mon:月1-12>tm_mday:日1-31>tm_hour:时0-23>tm_min:分0-59>tm_sec:秒0-59>tm_wday:星期0-6(0表示周日)>tm_day:一年中的第几天1-366>tm_isdst:是否是夏令,默认为-1二.ti

Yum! Brands expands rollout of Voice AI for faster, more accurate drive-thru orders to more Taco Bell locationsYum! Brands expands rollout of Voice AI for faster, more accurate drive-thru orders to more Taco Bell locationsAug 02, 2024 am 09:17 AM

Yum! Brands will expand the rollout of its Voice AI for faster, more accurate drive-thru orders to more Taco Bell locations this year. This follows two years of real-world testing at 100 select US locations across 13 states. The AI relieves human sta

如何解决 golang 中的 “undefined: time.After” 错误?如何解决 golang 中的 “undefined: time.After” 错误?Jun 25, 2023 pm 05:28 PM

Golang是一门非常受欢迎的编程语言,其简单易学、高效快速的特性吸引了越来越多的开发者。但在使用中,不可避免地会遇到一些问题和错误。例如,使用time包中的After方法时,可能会遇到undefined:time.After的错误。本篇文章将为大家介绍如何解决这个错误。了解错误原因在Golang中,如果我们使用了一个未导出的函数名或未正

使用PHP函数 "time" 返回当前的UNIX时间戳使用PHP函数 "time" 返回当前的UNIX时间戳Jul 25, 2023 pm 04:42 PM

使用PHP函数"time"返回当前的UNIX时间戳UNIX时间戳是指从协调世界时(UTC)1970年1月1日0时0分0秒起至今的总秒数。在PHP中,可以使用内置函数"time"来获取当前的UNIX时间戳。本文将介绍如何使用这个函数,并提供相应的代码示例。代码示例:<?php$timestamp=time();echo"当前的

Go语言基础之time包详解Go语言基础之time包详解Jul 21, 2023 pm 01:27 PM

time.Now()返回的是一个Time类型。有时候别人给我们的是时间戳,我们需要反着转以下,时间戳-时间类型。需要用到的是time.Unix。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools