Advertisement

06.01.2007 at 05:31AM PDT, ID: 22606788 | Points: 125
[x]
Attachment Details

Date string/month comparison

Zones: MySQL, Actuate
Tags: month, date, comparison
Dear experts,

I have a field with a date in but it is in a string format as follows: yyyymmdd e.g. 20070531.

I wish to do a comparison in my query so that the results from my query would equal the current months date.

how do i do this using the date filed above?

Thanks
Start your free trial to view this solution
Question Stats
Zone: Database
Question Asked By: Ritesh_Mistry
Question Asked On: 06.01.2007
Participating Experts: 3
Points: 125
Views: 0
Translate:
Loading Advertisement...
06.01.2007 at 05:51AM PDT, ID: 19194595

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.07.2007 at 10:04AM PDT, ID: 19235282

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.08.2007 at 01:04AM PDT, ID: 19240235

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.09.2007 at 12:39AM PDT, ID: 19247680

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.11.2007 at 04:05AM PDT, ID: 19257145

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.11.2007 at 01:42PM PDT, ID: 19261659

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.20.2007 at 11:15AM PDT, ID: 19930344

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.20.2007 at 11:58AM PDT, ID: 19930760

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
06.01.2007 at 05:51AM PDT, ID: 19194595
 
06.07.2007 at 10:04AM PDT, ID: 19235282

Rank: Master

You would need to convert the string column to a date

--- get records for todays date
SELECT *
FROM    YourTable
WHERE   str_to_date(YourStringColumn, '%Y%m%d') = current_date()

--- get records between first of this month and last day of this month
WHERE  str_to_date(YourStringColumn, '%Y%m%d') >=
                   date_add(current_date(), INTERVAL -day(current_date())+1 DAY)
AND    str_to_date(YourStringColumn, '%Y%m%d') <
           date_add(current_date()-day(current_date())+1, INTERVAL 1 MONTH)
 
06.08.2007 at 01:04AM PDT, ID: 19240235
agx,

I keep receiving a "missing right parenthesis" error. I've checked through andf typed in exactly what you have.
 
06.09.2007 at 12:39AM PDT, ID: 19247680

Rank: Master

Ritesh_Mistry,

Sorry for the delayed response.  I missed your reply.

I tried both queries and they work in mySql 5.  What version of mysql are you using? I think the STR_TO_DATE function requires at least v4.1.1.


mysql> SELECT  *
    -> FROM    YourTable
    -> WHERE  str_to_date(YourStringColumn, '%Y%m%d') >=
    -> date_add(current_date(), INTERVAL -day(current_date())+1 DAY)
    -> AND    str_to_date(YourStringColumn, '%Y%m%d') <
    -> date_add(current_date()-day(current_date())+1, INTERVAL 1 MONTH)
    -> ;
+------------------+
| YourStringColumn |
+------------------+
| 20070609         |
+------------------+
1 row in set (0.00 sec)
 
06.11.2007 at 04:05AM PDT, ID: 19257145
agx,

Apologies i wasn't clear from the start.

I'm actually using Actuate E Reporting to make a report.

Not sure which version.
 
06.11.2007 at 01:42PM PDT, ID: 19261659

Rank: Master

I'm not familiar with Actuate E Reporting, but the basic query logic still applies.  

Though on second thought it sounds like maybe your table contains a DATETIME column and you're just trying to pass in a string date parameter.   In which case you could pass in the first and end of the month like this

SELECT  *
FROM     YourTable
WHERE   YourDateColumn >= '2007-05-01' AND
             YourDateColumn <= '2007-05-30'

... or if your column contains date and time

SELECT  *
FROM     YourTable
WHERE   YourDateColumn >= '2007-05-01' AND
             YourDateColumn < '2007-06-01' -- less than first of NEXT month
 
09.20.2007 at 11:15AM PDT, ID: 19930344
Build some basic Time/Date functions into a library to include in your reports
 
     ' FILE NAME : TimeFunctions.bas
     '
     ' DESCRIPTION : This file implements some basic functions for Time/date for Actuate
     '
     '
     '-------------------------------------------------------------------------
     ' TfDatefromStamp(String) - Convert a String in the form 'yyyymmdd' into a date
     '-------------------------------------------------------------------------
     Function TfDatefromStamp(
     +   InputString As String
     +   ) As Date
         TfDatefromStamp =  CDate(Str$(Mid$(InputString,5, 2) & "/" & Mid$(InputString, 7, 2) & "/" & Mid$(InputString, 1, 4)))
     End Function
     '
     '-------------------------------------------------------------------------
     ' TfStampFromDate(Date)   - Convert a Date into string in the form yyyymmdd
     '-------------------------------------------------------------------------
     Function TfStampFromDate(
     +   InputDate As Date
     +   ) As String
         TfShorTftamp =  Format( InputDate, "yyyymmdd" )
     End Function
     '
     Function TfMonthEndDate(
     +  InputDate As Date
     +  ) As Date
        TfMonthEndDate = InputDate  'assign Date to input date
        TfMonthEndDate = CDate(str$(Month(TfMonthEndDate)) & "/1/" & str$(Year(TfMonthEndDate))) ' set to first of month
        TfMonthEndDate = DateAdd("m",1,TfMonthEndDate)  ' set to first of next month
        TfMonthEndDate = DateAdd("d",-1,TfMonthEndDate) ' set to end of this month
     End Function
     '
     Function TfMonthStartDate(
     +  InputDate As Date
     +  ) As Date
        TfMonthStartDate = InputDate  'assign Date to input date
        TfMonthStartDate = CDate(str$(Month(TfMonthStartDate)) & "/1/" & str$(Year(TfMonthStartDate))) ' set to first of month
     '
     End Function
     '
     Function TfMonthEndStamp(
     +  InputDate As Date
     +  ) As String
        TfMonthEndstamp = TfStampFromDate(TfMonthEndDate(InputDate))
     End Function
     '
     Function TfMonthStartStamp(
     +  InputDate As Date
     +  ) As String
        TfMonthStartStamp = TfStampFromDate(TfMonthStartDate(InputDate))
     End Function
     
You Can Then Override(Replace) the WhereClause In ObtainSelectStatement Function of SQLQuerySource

     Function ObtainSelectStatement( ) As String

        'Replace the where clause
         WhereClause = " YourStringColumn >= '" & TfMonthStartStamp(Date) & "' AND  YourStringColumn <= '" & TfMonthEndstamp(Date) & "'"

       'Build the SQL statement the clauses
       
        ObtainSelectStatement = Super::ObtainSelectStatement( )

        '  Show the statement in the job summary if desired
           '  ShowFactoryStatus(ObtainSelectStatement)

     End Function

Uncomment the ShowFactoryStatus To debug the SQL
 
09.20.2007 at 11:58AM PDT, ID: 19930760
Typo in function:

     '-------------------------------------------------------------------------
     ' TfStampFromDate(Date)   - Convert a Date into string in the form yyyymmdd
     '-------------------------------------------------------------------------
     Function TfStampFromDate(
     +   InputDate As Date
     +   ) As String
         TfStampFromDate =  Format( InputDate, "yyyymmdd" )
     End Function
 
 
20080236-EE-VQP-29