how to set datetime now() in telnet

i need to do this:

mysql> alter table ApReq modify TimeStamp datetime now();
 i can't get the now() part -
phillystyle123Asked:
Who is Participating?
 
SqueebeeCommented:
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
 
ikeworkCommented:
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
 
SqueebeeCommented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
phillystyle123Author Commented:
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
 
phillystyle123Author Commented:
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
 
phillystyle123Author Commented:
so there is no way to set datetime default to now() in mysql?
0
 
SqueebeeCommented:
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
 
phillystyle123Author Commented:
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
 
SqueebeeCommented:
Oh, I should have mentioned that no, you can't.
0
 
phillystyle123Author Commented:
why not?
0
 
ikeworkCommented:
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
 
SqueebeeCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.