douchen4547 2013-11-07 18:00
浏览 152

MySQL自定义时间戳值

I'm having some troubles dealing with Timestamp data type in MySQL.

I'm saving simple records in my database using a simple DB structure, like:

ID   int
Name varchar
Date timestamp
Text varchar

And then retrieve them with something like:

SELECT * FROM table WHERE Date BETWEEN '2013-01-01' AND '2013-06-30'

Everything works fine if I store records letting MySQL fill the Date field with the actual timestamp, for example: 2013-10-04 22:40:02 which means I don't add any value to the Date field in my INSERT query.

But I need to be able to add the date by my self since my application needs to store the date from where the application started, and not the date and time in which the query was sent to the database. So what I do is I create the same date/time format my Date field uses which is 2013-10-04 22:40:02 and then do a simply insert:

INSERT INTO table (Name, Date, Text)
VALUES ('Peter', '2013-10-04 22:40:02', 'Hello...')

Now, doing it this way I'm unable to bring any result by date using a select query like this one:

SELECT * FROM table WHERE Date BETWEEN '2013-01-01' AND '2013-11-30'

Even if I try to sort results by Date using PHPMyAdmin interface, all the records that contain manually added dates disappear. If I sort them by ID, they re-appear. I checked and the dates and formats are correct. So I have no idea what the problem could be. I'm new at MySQL by the way.

Hope you can give me a hand. Thanks!

  • 写回答

1条回答 默认 最新

  • dqmq0654 2013-11-07 18:37
    关注

    Well, I think I found the problem and it has nothing to do with PHP and MySQL, the problem is that I generate the date with JavaScript, and it's giving the wrong month.. :/

    Thanks to everyone anyway!

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配