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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。