LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-03-2006, 12:38 AM   #1
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Rep: Reputation: 30
Exclamation Getting Day of Week - Java - SQL Date


Hi,
I am currently using java.sql.Date as my default date for compatibility with mysql database. I want to get the day in string of any particular date. E.g 2006-04-03 should return "Monday". I am using this for some validations where the user inputs the day name i.e Mondey,Tuesday... and afterwards when they enter a certain date and my application must check if that day is correct.
 
Old 04-03-2006, 12:56 AM   #2
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
In Java, the day of the week are Integers. 1 is Sunday, 2 is Monday, ..., and 7 is Saturday. I'm not sure if this will be the same with sql.Date, but you can try it

Code:
import java.util.*;

public class MainClass {

    public static void main(String[] args) {
	
        Calendar calender = new GregorianCalendar(2006, Calendar.APRIL, 3);
        int dayOfWeek = calender.get(Calendar.DAY_OF_WEEK);    
	    
	System.out.println(dayOfWeek); // This will return 2. 2=Monday

    }

}

Last edited by Mega Man X; 04-03-2006 at 12:58 AM.
 
Old 04-03-2006, 06:07 AM   #3
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Original Poster
Rep: Reputation: 30
Thanks Mega Man X! Its so stupid of me not to think about the Calander methods in java.util. I've already used it some time back with java.sql.Date and it surely works! Thanks Again...
 
Old 04-03-2006, 07:17 AM   #4
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
You're welcome MRMadhav!. I'm glad it works. By the way, thanks for replying. I soon will try to build a JSP page with SQL and now I know this will work later for me as well
 
Old 04-03-2006, 12:01 PM   #5
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Original Poster
Rep: Reputation: 30
Sure Am glad that this will help you too, but remember one thing when you use:
import java.sql.*;

and you are using the Date function, don't put

import java.util.*;

as both have the same method for date but each respond differently!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
oracle + working with date/week champ Programming 8 11-28-2011 05:45 PM
Multicount in PHP , displays visits on current day, week, month, year and total visit xbaez Programming 1 04-24-2005 02:50 AM
Schedule by day of the week stand Linux - General 1 08-30-2004 11:49 PM
date command getting previous day swinchen Programming 6 08-23-2004 12:17 PM
Setting date day names Dark Carnival Linux - General 3 12-07-2003 01:22 PM


All times are GMT -5. The time now is 09:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration