Welcome to Kodok Marton's homepage

Professional work from professionals!

  • Increase font size
  • Default font size
  • Decrease font size
Home Programming
Programming


How to properly get user's birthday from database (solution for 29th February)

Today, I came across a problem, where I had to get from database all users that celebrate today. This is not as easy as it sounds, as there are leap years, and users having their birthday on 29th February will be returned only in 4 years. It's better return them on 1st March if the 29th February doesn't exists in that year. Actually, if you need to be serious about this, you have to take into account, that every 100 years, there's no leap year, but every 400 there is. 

Here is an answer that property takes into account leap-years and will always give you the users whose birthday is on the 29th of February at the same time as those on the 1st of March.

SELECT * 
  FROM USERS
  WHERE
     DATE_FORMAT
(FROM_UNIXTIME(birthDate),'%m-%d') = DATE_FORMAT(NOW(),'%m-%d')
     OR
(
           
(
                DATE_FORMAT
(NOW(),'%Y') % 4 <> 0
                OR
(
                        DATE_FORMAT
(NOW(),'%Y') % 100 = 0
                        AND DATE_FORMAT
(NOW(),'%Y') % 400 <> 0
                   
)
           
)
            AND DATE_FORMAT
(NOW(),'%m-%d') = '03-01'
            AND DATE_FORMAT
(FROM_UNIXTIME(birthDate),'%m-%d') = '02-29'
       
)

 

 

What makes each major language “special”?

It's been said that any language that doesn't change your way of thinking about programming isn't worth learning. It would be interesting to compile a list of what makes every major language "special". These would be the features that are unique to the language (at least compared to languages of similar or greater popularity and/or in terms of the level of emphasis placed on them), that one has to understand to "think in" the language, and that make the language worth learning even if you can't make any money by learning it. Here are some examples:

  • C: Pointers, manual memory management, low-level unchecked programming.
  • C++: RAII, templates.
  • D: Templates on steroids, compile time function evaluation, insanely powerful compile time introspection/reflection, the ability to program at a very high level and a very low level in the same language.
Read more...
 

What should a developer know before building a public web site?

The idea here is that most of us should already know most of what is on this list. But there just might be one or two items you haven't really looked into before, don't fully understand, or maybe never even heard of.

Read more...
 


Page 2 of 2