date-format

Return null for date_format when input is null in mysql

浪尽此生 提交于 2019-12-01 16:15:19
I'm doing something like this: SELECT date_format(mydate, '%d/%m/%Y') FROM xyz; When mydate is NULL, date_format returns 00/00/0000. This is correct, but how can I make it so that it returns NULL when the input is NULL? SELECT IF(mydate,date_format(mydate, '%d/%m/%Y'),NULL) FROM xyz; Source: http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html You can wrap this into a IF -Clause, like this: SELECT IF(mydate,DATE_FORMAT(mydate, '%d/%m/%Y'),NULL) FROM xyz; That said, if your variable mydate is not a date value, the query in your post should return (NULL) anyway. select case when

mysql query - format date on output?

拈花ヽ惹草 提交于 2019-12-01 13:42:31
In my table, dates are stored like this: 2011-03-03T13:30:00 I'm trying to output dates like this: March 3, 2011 1:30 PM I'd much rather work it into the query rather than use php to format it, but I'm having some difficulty doing that. Trying various iterations of DATE_FORMAT, but it's not giving me what I want, maybe because of the way it's being stored? You basically have two different operations you may need to perform when handling dates: date to string and vice versa. The functions you can use are DATE_FORMAT() and STR_TO_DATE() . Full reference can be found in the manual . Usage example

Java date format

自古美人都是妖i 提交于 2019-12-01 13:39:55
Have String str "May 23 2011 12:20:00", want to convert it to date such this: Date date = (new SimpleDateFormat("MMM dd yyyy HH:mm:ss")).parse(str); It always gives me ParseException Unparsable date format: 'May 23 2011 12:20:00'. Looked for similar issues, seems everything right. What is wrong? You may need to additionally specify the Locale , when the default Locale of your VM is not an English one: Date date = (new SimpleDateFormat("MMM dd yyyy HH:mm:ss", Locale.US)).parse(str); Works for me.! Try specifying locale while constructing SimpleDateFormat object. Basil Bourque tl;dr

Fill missing date values in column by adding delivery interval to another date column

為{幸葍}努か 提交于 2019-12-01 12:58:08
问题 Data: DB1 <- data.frame(orderItemID = 1:10, orderDate = c("2013-01-21","2013-03-31","2013-04-12","2013-06-01","2014-01-01", "2014-02-19","2014-02-27","2014-10-02","2014-10-31","2014-11-21"), deliveryDate = c("2013-01-23", "2013-03-01", "NA", "2013-06-04", "2014-01-03", "NA", "2014-02-28", "2014-10-04", "2014-11-01", "2014-11-23")) Expected Outcome: DB1 <- data.frame(orderItemID = 1:10, orderDate= c("2013-01-21","2013-03-31","2013-04-12","2013-06-01","2014-01-01", "2014-02-19","2014-02-27",

Convert decimal year to date

喜夏-厌秋 提交于 2019-12-01 12:24:18
I have dates in a table that are stored as decimal years . An example is 2003.024658 which translates to January 9, 2003 . I would like to convert the decimal years to Oracle's date format. I've found someone who's done this in Excel: Decimal year to date formula? =DATE(INT(B1),1,MOD(B1,1)*(DATE(INT(B1)+1,1,1)-DATE(INT(B1),1,1))) However, I can't quite figure out how to convert the logic to Oracle PL/SQL. If you start from the assumption that the decimal portion was calculated according to the number of days in the given year (i.e. 365 or 366 depending on whether it was a leap year), you could

How do I display MM/dd/yyyy (no time) in my DataGridView column?

99封情书 提交于 2019-12-01 11:12:03
问题 I need help on my DataGridView column date format. I want the date to be "MM/dd/yyyy". I dont need the time. How can this be done programmatically? i have tried this code but it doesn't work gridView.Columns[1].DefaultCellStyle.Format = "MM/dd/yyyy"; `var connSettings = ConfigurationManager.ConnectionStrings["MyDB"]; { string CN = connSettings.ConnectionString; MySqlConnection conn = new MySqlConnection(CN); MySqlCommand cmd = new MySqlCommand("select id, entry_datetime, CONCAT(last_name, ' '

PHP: Help with this date formatting

混江龙づ霸主 提交于 2019-12-01 10:27:05
I have an application I'm building with CodeIgniter. I have records in a SQL Server DB which have datetime fields. I'm querying these records from dates entered into a textfield in the m/d/Y. This corresponds to the date format in the db. Unfortunately I'm in the UK! So I want to enter dates in like d/m/Y. So I need to capture this, format it into the appropriate format and then validate it. Here's the code in using to format: $datestring = "%m/%d/%Y"; if(isset ($_POST['from_date']) AND isset ($_POST['to_date'])){ $from = mdate($datestring, strtotime($_POST['from_date'])); $to = mdate(

Convert date in local timezone using javascript

混江龙づ霸主 提交于 2019-12-01 10:22:12
问题 In my JavaScript layer, I am receiving a timestamp which is in UTC format - and I need to convert it for the local timezone . I know that the timezone can be converted using DateFormat on the Java side, but I am looking for a reliable way to do it using only JavaScript. Any suggestions would be very appreciated. 回答1: Use getTimezoneOffset() Obtain local UTC offset and convert to msec localOffset = d.getTimezoneOffset() * 60000; Note that a negative return value from getTimezoneOffset()

highcharts tooltip wrong date

核能气质少年 提交于 2019-12-01 10:12:43
I had made one highchart in that tooltip is shows date and time in format but it is showing wrong date and time. Please go through the code below. HTML Code <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> Javascript Code var maxval="94"; $(function () { var chart; $(document).ready(function() { chart = new Highcharts.Chart({ credits: {

PHP: Help with this date formatting

Deadly 提交于 2019-12-01 09:38:50
问题 I have an application I'm building with CodeIgniter. I have records in a SQL Server DB which have datetime fields. I'm querying these records from dates entered into a textfield in the m/d/Y. This corresponds to the date format in the db. Unfortunately I'm in the UK! So I want to enter dates in like d/m/Y. So I need to capture this, format it into the appropriate format and then validate it. Here's the code in using to format: $datestring = "%m/%d/%Y"; if(isset ($_POST['from_date']) AND isset