Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to set datetime now() in telnet

Posted on 2003-10-29
12
Medium Priority
?
1,014 Views
Last Modified: 2008-03-10
i need to do this:

mysql> alter table ApReq modify TimeStamp datetime now();
 i can't get the now() part -
0
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 20

Expert Comment

by:ikework
ID: 9645472
in mysql timestamp is a datatype itsself, so you can declare a field, which is updated
with every insert and update, depending on the running mode of mysql
(for further details llook at http://www.mysql.com/doc/en/DATETIME.html )

create table your_table(the_timstamp_field timestamp);


i guess, what you wanted to do is to set the default-value of your field to now(), to do it try this:

alter table ApReq modify TimeStamp datetime default now();

not sure, if it works, cauz TimeStamp is a keyword of mysql... good luck


hope this helps :)

maik
0
 
LVL 17

Expert Comment

by:Squeebee
ID: 9645551
But then should the default be the current value of now() or always be the current time?
Like ikework said, if you are trying to create a timestamp of the updates on the row use a TIMESTAMP type column, it will update to the current time with every update of the row.
0
 

Author Comment

by:phillystyle123
ID: 9645593
it doesn't work.  I have managed to successfully change the field's type to datetime though so I don't think TimeStamp is a problem.  it's just the now() part that doesn't seem to be working.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:phillystyle123
ID: 9645609
i think i need to use datetime because every time i'm updating some table info using odbc linked to access and with timestamp everytime i update something it changes the date to the current date.  
0
 
LVL 17

Accepted Solution

by:
Squeebee earned 200 total points
ID: 9645678
That is what a TIMESTAMP field does, do you just want a timestamp of the time the row was first created?

You could still use timestamp, and in any subsequent UPDATE queries always

SET timestampcol = timestampcol

Which will keep the timestamp column the same so it does not update.

Otherwise you can always use NOW() in the INSERT queries.
0
 

Author Comment

by:phillystyle123
ID: 9645699
so there is no way to set datetime default to now() in mysql?
0
 
LVL 17

Expert Comment

by:Squeebee
ID: 9645765
Well, what you can do is create two TIMESTAMP fields, call the first one update time and the second one create time. As you can see in the example below, when you have more than one timestamp column, they will both catch the current time during row creating, but only the first one catches the new time during UPDATE queries.

---------------------------------------------------------------------------------

mysql> create table temptime(time1 timestamp, time2 timestamp);
Query OK, 0 rows affected (0.13 sec)

mysql> insert into temptime VALUES(NULL,NULL);
Query OK, 1 row affected (0.02 sec)

mysql> insert into temptime VALUES(NULL,NULL);
Query OK, 1 row affected (0.00 sec)

mysql> insert into temptime VALUES(NULL,NULL);
Query OK, 1 row affected (0.00 sec)

mysql> select * from temptime;
+---------------------+---------------------+
| time1               | time2               |
+---------------------+---------------------+
| 2003-10-29 14:35:59 | 2003-10-29 14:35:59 |
| 2003-10-29 14:36:02 | 2003-10-29 14:36:02 |
| 2003-10-29 14:36:03 | 2003-10-29 14:36:03 |
+---------------------+---------------------+
3 rows in set (0.00 sec)

mysql> update temptime set time1 = now();
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> select * from temptime;
+---------------------+---------------------+
| time1               | time2               |
+---------------------+---------------------+
| 2003-10-29 14:36:37 | 2003-10-29 14:35:59 |
| 2003-10-29 14:36:37 | 2003-10-29 14:36:02 |
| 2003-10-29 14:36:37 | 2003-10-29 14:36:03 |
+---------------------+---------------------+
3 rows in set (0.00 sec)
0
 

Author Comment

by:phillystyle123
ID: 9646081
Squeebee  - thanks for the code but i already have the thing up and running so i'd rather not go to all this trouble if i can just do datetime now().
0
 
LVL 17

Expert Comment

by:Squeebee
ID: 9646188
Oh, I should have mentioned that no, you can't.
0
 

Author Comment

by:phillystyle123
ID: 9646214
why not?
0
 
LVL 20

Expert Comment

by:ikework
ID: 9646316
i guess mysql doesn't think this case doesn't worth to be implemented,
i can understand that, cauz you can simply do it in your insert statement,
why don't you do it this way?

insert into your_table(datefield)values(now());
0
 
LVL 17

Expert Comment

by:Squeebee
ID: 9646331
MySQL did not anticipate the need I suppose. Between TIMESTAMP for auto updated fields and DATETIME for static fields that have most of their bases covered, and the remaining users either use two TIMESTAMP fields like I suggested, or INSERT NOW() like ikework suggested.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question