How do you set a default value for a MySQL Datetime column? How do you set a default value for a MySQL Datetime column? In SQL Server it's getdate(). What is the equivalant for MySQL? I'm using MySQL 5.x if that is a factor. Answer: IMPORTANT EDIT: It is now possible to achieve this with DATETIME fields since MySQL 5.6.5, take a look at the other post below... Previous versions can't do that with DATETIME... But you can do it with TIMESTAMP: mysql> create table test (str varchar(32),
undefined
How do you get a timestamp in JavaScript? How can I get a timestamp in JavaScript? Something similar to Unix's timestamp, that is, a single number that represents the current time and date. Either as a number or a string. Answer: Short & Snazzy: + new Date() A unary operator like plus triggers the valueOf method in the Date object and it returns the time-stamp (without any alteration). Details: On almost all current browsers you can use Date.now() to get the UTC timestamp in milliseconds; a notable exception to this is IE8
undefined
How to get the current date and time in PHP? Which PHP function can return the current date/time? BEST Solution : The time would go by your server time. An easy workaround for this is to manually set the timezone by using date_default_timezone_set before the date() or time() functions are called to. I'm in Melbourne, Australia so I have something like this: date_default_timezone_set('Australia/Melbourne'); Or another example is LA - US: date_default_timezone_set('America/Los_Angeles'); You can also see what timezone the server is currently in via: date_default_timezone_get(); So something like: $timezone = date_default_timezone_get(); echo "The
undefined
How to return the date part only from a SQL Server datetime datatype SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 00:00:00.000 Answer: On SQL Server 2008 and higher, you should convert to date: SELECT CONVERT(date, getdate()) On older versions, you can do the following: SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, @your_date)) for example SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) gives me 2008-09-22 00:00:00.000 Pros: No varchar<->datetime conversions required No need to think about locale http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype
undefined
PHP: DATETIME Help I know there's ample information about datetimes on the internet but I'm having trouble using what I've been seeing. I have a calander control hooked up to a text box. It takes it in the form 15/11/2010 (british). I use it to query datetime fields in a SQL server db in the format 15/11/2010 00:00:00. After the capture the dates on postback I pass the values onto my method that attempts to convert the text into time format. When I
undefined
PHP DateTime Update I'm using PHP > 5.3 and i have a question in respect of DateTime: First i'm not able to use: $date = new DateTime('2012-06-08 00:00:00'); $t = $date->createFromFormat('Y/m/d', '2012-06-11 23:59:59'); I get the following error message: Call to undefined method DateTime::createFromFormat() I can use other function in that class. The second thing i'm puzzled about how to update the object initial date, or do i have to create a new object? Answer: createFromFormat is a static method of DateTime so you