Solved

how to set datetime now() in telnet

Posted on 2003-10-29
12
1,012 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 50 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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