473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

mysql insert current date and time

123 100+
I using a insert query to insert some data into mysql.

I use now() as the current date and time but it always have 3.X hours different from actual date.

what i should use instead?

thanks.
Jun 18 '09 #1
3 11832
Atli
5,058 Expert 4TB
Hi.

Is your server perhaps located +3 time-zones away from your local time?

The NOW() function inserts the current time according to the time on the server machine and the timezone settings on the MySQL server itself.

There are several ways to specify the timezone.
See 9.7. MySQL Server Time Zone Support

If you have root-like (super) privileges on the server, you can issue this command to set the timezone:
Expand|Select|Wrap|Line Numbers
  1. SET GLOBAL time_zone = timezone;

If you aren't up for all that, you could just use the DATE_SUB, DATE_ADD or CONVERT_TZ functions to correct the difference in your queries.

Like, if your local timezone is GMT and the server is 3 hours ahead:
Expand|Select|Wrap|Line Numbers
  1. /* You could either do: */
  2. SELECT CONVERT_TZ(NOW(), '+03:00', '+00:00');
  3.  
  4. /* Or: */
  5. SELECT DATE_SUB(NOW(), INTERVAL 3 HOUR);
Both would return the date 3 hours prior to the current date on the server.

And you can of course you both of those in an INSERT statement as well.
(Although, I never feel right altering data before INSERTing it. I like to do it on the way out.)
Jun 18 '09 #2
perhapscwk
123 100+
thanks...I will use DATE_ADD instead..thanks alot
Jun 19 '09 #3
Atli
5,058 Expert 4TB
Glad I could help :)
Jun 19 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: vishal | last post by:
i want to store the date and time when the user registered i.e. the record is entered in my table. so how can i achieve this???? should i use php or mysql to achieve this?? which is more...
2
by: toedipper | last post by:
Hello, I have the following section of php code which updates a mysql record from a form. For the values of livedate and livetime I need to insert the current_date() and current_time()...
5
by: ryan.mclean | last post by:
Hi all, I have a question about inserting records into sql server. I am brand new to sql server, always using oracle previously. Before today, I had always written statement such as this: ...
2
by: mattmerc | last post by:
Hi, I would like to have a date_last_modified field for one of my SQL tables. Instead of coding my front end to keep up with this field is there a way to user a formula for this column in...
2
by: lphuong | last post by:
Access 2000 I have a fldCreateDate on frmCustomer(mainform)and also a fldCreateDate on frmCustomerVisit(subform). They are one to many relationship. On the main form, frmCustomer, I have a...
1
by: George LAZAR | last post by:
how can I change the system current date (time) using c#? thank you George
3
by: William Cruz | last post by:
Is there a way to get the current date / time on a remote PC? William *** Sent via Developersdex http://www.developersdex.com ***
6
by: trytobreak | last post by:
Hi All, I am a network administrator in a fairly large software company and I would like to write myself a small utility, which would connect (one by one) to all machines on the network and get...
12
by: AccessBeetle | last post by:
I have a qry bound form showing the search results based on the user entered criteria. There is a button called Edit on that form. The form is locked initally to stop user to edit any record...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.