12:19:05 AM
Thursday
Sep 09
Su M Tu W Th F Sa
567891011
12131415161718
19202122232425
262728293012
3456789

Play My Typing Game

View Some of My Artwork

an example of MySQL's SUBSTR function
I'm writing this tutorial because it took me awhile to figure out that MySQL's SUBSTR() function is not identical to PHP's substr(). SUBSTR(field, startChar, length) is the syntax, but instead of being zero based it starts at 1. Here's a real world example: imagine a db table with a field or column named dte, it is a datestamp such as YYYY-MM-DD and there are a lot of them... you only need to know the YYYY-MM pattern. Instead of using PHP, you can solve the puzzle closer to the core, by utilizing one of MySQL's built in functions.

Remember, MySQL's SUBSTR() function is not zero based, it starts at 1.

SELECT SUBSTR(dte, 1, 7) as ym FROM table ORDER BY dte DESC GROUP BY ym;


This returns a MySQL result with a record of each unique YYYY-MM pattern which was found.

Google mysql string functions for some more great info.


Read Previous:
simple form and action
Read Next:
Go Back Link
Table of Contents


Give a listen to my music...
My Best Recordings
How my services and skills can help you:
  • Global (via Email/Skype/AIM(ichat)/Yahoo)
    • Web Development Consulting
    • Custom Web App Development (PHP/MySQL/jQuery/CSS) Cross-Browser & OS
    • Cellphone App Development (Android/MobileWeb)
    • Music Lessons & Education for Beginner Guitar, Piano, Bass, which transfers over to many other instruments I am comfortable playing but not yet at teaching.
    • Music - Soundtrack Composition & Voice Work
  • Local
    • Most all the above, but also:
      • Music Performance (Harp, Voice, Guitar, Piano, Bass, Latin Percussion)
      • Recording Live Music Audio
      • Video Streaming live music and other live events anywhere that can provide wifi
      • Training Video Streaming to your venue's trusted soundperson
Skills:
  • Global (via Email/Skype/AIM(ichat)/Yahoo)
    • Web Development Consulting
    • Custom Web App Development (PHP/MySQL/jQuery/CSS) Cross-Browser & OS
    • Cellphone App Development (Android/MobileWeb)
    • Music Lessons & Education for Beginner Guitar, Piano, Bass, which transfers over to many other instruments I am comfortable playing but not yet at teaching.
    • Music - Soundtrack Composition & Voice Work
  • Local, Most all the above, but also:
    • Music Performance (Harp, Voice, Guitar, Piano, Bass, Latin Percussion)
    • Being your venue's soundman
    • Video Streaming live music and other live events anywhere that can provide wifi
    • Training Video Streaming to your venue's trusted soundperson