Date calculation

Discussion in 'Software' started by be0, Feb 8, 2007.

  1. be0

    be0 Corporal

    Hi there,

    I need some professional help. Give a date in numeric format YYYYMMDD I would like to calculate the number of days between 2 given dates.
    Is there a mathematical formula that can be used? Or is there a SQL converison statement that can be used? How would one do it?

    Example:

    20070208 Feb 8, 2007
    and
    20060503 May 3, 2006

    a simple a - b does not give me the correct number of days.
     
  2. be0

    be0 Corporal

    Also another question:

    How would you use SQL to convert from a number to date if a date was in number format like YYYYMMDD?
     
  3. Publius

    Publius Sergeant

    Try the datediff function. You shouldn't need to convert it.

    select datediff('20070208', '20060503');
     

    Attached Files:


MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds