473,670 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql insert current date and time

123 New Member
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 11845
Atli
5,058 Recognized Expert Expert
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 New Member
thanks...I will use DATE_ADD instead..thanks alot
Jun 19 '09 #3
Atli
5,058 Recognized Expert Expert
Glad I could help :)
Jun 19 '09 #4

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

Similar topics

3
3061
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 proper and how can i get date-time ???
2
10073
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() respectively. When I run the code however it falls over at the line with GetSQLValueString(current_date(), "date")
5
165934
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: INSERT INTO TABLE (COL1) VALUES SYSDATE; How is this accomplished in sql? I am using a datetime data type, I hope that is correct . . . Thank you for your help.
2
6722
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 Enterprise Manager so that each time a record is created or updated the current date/time will be inserted/updated? I tried using getdate() but then the field always has the current time, which is not what I am looking for. I am looking for the time...
2
7648
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 Before Insert event call a MacroCustomerCreateDate Action: setvalue Item: !! Expression: Date( ) This is working fine; I got the current date as soon as I input
1
6218
by: George LAZAR | last post by:
how can I change the system current date (time) using c#? thank you George
3
1977
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
9539
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 their current date and time stamps. This is mostly because of coming DST changes and having hundreds of machines on the network, I don't want to connect remotely to every and each server to see if the time is correct.
12
3164
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 accidentally. When user clicks on edit, all the controls go unlocked and user can edit the record. There three fields on the form showing who entered data (ModeUserId, ModeDate, ModeTime). I want these fields to change there value accordingly(meaning it...
0
8468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8901
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8660
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.