×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Update column based on input from another column
3

Update column based on input from another column

Update column based on input from another column

(OP)
In my mysql DB, I have a field (current_) that automatically defaults as the current date/time. This happens each time there is a new entry.
I have another field (next_) that I want to be the current date/time + 4 hours.
I have tried this using code(classic asp) as well as using unix time. Because asp cannot format to yyyy-mm-dd as it is in the DB, this won't work. I cannot use unix time because classic asp has a difficult time converting back to standard date/time from UNIX time.

If there a way to have this script nested, OR RUN AS A STORED PROCEDURE in the DB??


Thanks,
Penguin
Please keep in mind that I am using classic ASP with MySQL database. Not sure if that information helps or not.

RE: Update column based on input from another column

Hi

The bigger question would be your MySQL's version. If it is 8.0.13 or newer, you can use expression in the default clause :

CODE --> MySQL 8.0.13

create table penguinspeaks (
    current_ datetime default current_timestamp,
    next_ datetime default (current_timestamp + interval 4 hour) -- parenthesis mandatory for expressions
); 

If you have older MySQL, you will have to use a trigger :

CODE --> MySQL

create trigger penguinspeaks_next
before insert on penguinspeaks for each row 
set new.next_ = current_timestamp + interval 4 hour; 

Feherke.
feherke.github.io

RE: Update column based on input from another column

2
I would use a virtual column instead. No code needed, no trigger needed, just set it up and forget about it... smile

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Update column based on input from another column

Hi

Thank you, Andy. medal Somehow I completely missed them until now.

Feherke.
feherke.github.io

RE: Update column based on input from another column

... and once you know about them (virtual columns that is) you will ask yourself: "How could I've lived without them...?" smile2

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Update column based on input from another column

Hi

Quote (Andy)

... and once you know about them (virtual columns that is) you will ask yourself: "How could I've lived without them...?" smile2
Exactly that is the most maddening in it : I knew the feature for about 9 years from MSSQL's computed columns. banghead

Feherke.
feherke.github.io

RE: Update column based on input from another column

(OP)
Thanks for the ideas. I had to read up on virtual columns, but it solved my issues.

Thanks,
Penguin
Please keep in mind that I am using classic ASP with MySQL database. Not sure if that information helps or not.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close