Advertisements

Archive

Posts Tagged ‘date’

Age calculation in mysql Select query


Following is the way to calculate age based on date in mysql select query

SELECT name, 
birth, 
CURDATE(), 
TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age 
FROM 
TableName; 

+----------+------------+------------+------+ 
| name | birth | CURDATE() | age | 
+----------+------------+------------+------+ 
| Fluffy | 1993-02-04 | 2003-08-19 | 10 | 
| Claws | 1994-03-17 | 2003-08-19 | 9 |
| Buffy | 1989-05-13 | 2003-08-19 | 14 | 
| Fang | 1990-08-27 | 2003-08-19 | 12 | 
| Bowser | 1989-08-31 | 2003-08-19 | 13 | 
| Chirpy | 1998-09-11 | 2003-08-19 | 4 | 
| Whistler | 1997-12-09 | 2003-08-19 | 5 | 
| Slim | 1996-04-29 | 2003-08-19 | 7 | 
| Puffball | 1999-03-30 | 2003-08-19 | 4 | 

+----------+------------+------------+------+ 
Hope this is helpful !


Advertisements

Function to find dates in current week in mysql


MySQL YEARWEEK() returns year and week number for a given date.

Syntax: YEARWEEK(date_value,Mode)

Parameters or Arguments

date_value
A date or datetime value from which to extract the year and week.
mode
Optional. It is used to specify what day the week starts on. It can be one of the following:

mode Explanation Week Value
0 First day of the week is Sunday 0-53
1 First day of the week is Monday and the first week has more than 3 days 0-53
2 First day of the week is Sunday 1-53
3 First day of the week is Monday and the first week has more than 3 days 1-53
4 First day of the week is Sunday and the first week has more than 3 days 0-53
5 First day of the week is Monday 0-53
6 First day of the week is Sunday and the first week has more than 3 days 1-53
7 First day of the week is Monday 1-53

Example : select YEARWEEK(now());

The following statement will return the year and week number of the date 2016-05-19.

SELECT YEARWEEK(‘2016-05-19’);

 

mysql-yearweek-function

 

Hope this help!

Order by Date Descending issue (Linq)

February 12, 2016 Leave a comment

Issue :

 Dim list As List(Of Eventlist) = (From d In EventList
 Order By d.Status Descending, d.StartDate Descending, 
 Select d).ToList()

It gives me the date ordered by month and day, but doesn’t take year into consideration. for example:

12/31/2009 
12/31/2008
12/30/2009
12/29/2009

Needs to be more like:

12/31/2009
12/30/2009
12/29/2009
12/28/2009

Solution :

 Dim list As List(Of Eventlist) = (From d In EventList
 Order By d.Status Descending, Year(d.StartDate) Descending, Month(d.StartDate) Descending, Day(d.StartDate) Descending
 Select d).ToList()


Hope it helps !

Add Days to Javascript Date Object

November 19, 2015 Leave a comment

To add days to javascript date object use following syntax

var dayOffset = 20;

var millisecondOffset = dayOffset * 24 * 60 * 60 * 1000;

december.setTime(december.getTime() + millisecondOffset);

Bootstrap and datepicker

November 17, 2015 Leave a comment

How to check if the user enters the default datetime? VB.NET


In VB.NET if we pass nothing to date it will return default value like ” #12:00:00 AM# ‘

 

To check if date is not default date than following should be used

IfNotDate.MinValue = MyDate

 

Hope it helps

Categories: VB.NET Tags: , , ,