How to get Day of Week as String?

Visual Basic Topics
Post Reply
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

How to get Day of Week as String?

Post by Nandika » Sun Mar 04, 2012 11:57 pm

Hi Friends, :)

I want to know a function for get Day name as a String.like Sunday,Monday,....
this is for a module file.

like this,

Code: Select all

Public function getDay() as String
dim strday as String
'What am i type/coding in here???
getDay=strday
End Function
Anyone help me.
Thanxz
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: How to get Day of Week as String?

Post by Saman » Mon Mar 05, 2012 10:13 am

You can use WeekdayName for this.

strDOW = WeekdayName(6) will put "Friday" to strDOW.

Note: You can use MonthName function to return month as a string as well.

Try out these to get a good idea:

Code: Select all

Print "Now:"; Tab(30); Now
Print "Using DateValue:"; Tab(30); DateValue(Now)
Print "Using TimeValue:"; Tab(30); TimeValue(Now)
Print "Using Weekday:"; Tab(30); Weekday(Now)
Print "Using WeekdayName:"; Tab(30); WeekdayName(Weekday(Now))
Print "Using WeekdayName (abbrev.):"; Tab(30); WeekdayName(Weekday(Now), True)
Print "Using Month:"; Tab(30); Month(Now)
Print "Using MonthName:"; Tab(30); MonthName(Month(Now))
Print "Using MonthName (abbrev.):"; Tab(30); MonthName(Month(Now), True)
Print "Using Day:"; Tab(30); Day(Now)
Print "Using Year:"; Tab(30); Year(Now)
Print "Using Hour:"; Tab(30); Hour(Now)
Print "Using Minute:"; Tab(30); Minute(Now)
Print "Using Second:"; Tab(30); Second(Now)
If you are looking to get a part of date, have a look at following example:

Code: Select all

Print "Current date/time is: "; Format$(Now, "Long Date"); Spc(1); Format$(Now, "Long Time")
Print "*** DatePart Function Examples ***"
Print "Using 'yyyy':"; Tab(20); DatePart("yyyy", Now)
Print "Using 'q':"; Tab(20); DatePart("q", Now)
Print "Using 'm':"; Tab(20); DatePart("m", Now)
Print "Using 'y':"; Tab(20); DatePart("y", Now)
Print "Using 'd':"; Tab(20); DatePart("d", Now)
Print "Using 'w':"; Tab(20); DatePart("w", Now)
Print "Using 'ww':"; Tab(20); DatePart("ww", Now)
Print "Using 'h':"; Tab(20); DatePart("h", Now)
Print "Using 'n':"; Tab(20); DatePart("n", Now)
Print "Using 's':"; Tab(20); DatePart("s", Now)
I think that's all about VB date/time ;)
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: How to get Day of Week as String?

Post by Nandika » Mon Mar 05, 2012 8:26 pm

Saman wrote:
I think that's all about VB date/time ;)
Thanks lot Saman.. :clap:
Rally it may be correct. : :clap:

now i can build my function.Actually,this is for my friend.
I had some memory about this.But,really,i forgot it. :(
I could not test my memory.because, i haven't VB6 in my PC...

Thank you...
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: How to get Day of Week as String?

Post by Nandika » Mon Mar 05, 2012 8:45 pm

Saman,
Now,
Am i correct?
Will this function work in as i want?

Code: Select all

Public function getDay() as String
dim strday as String
strday=WeekdayName(Weekday(Now), True)'--Am i correct in this line?
getDay=strday
End Function
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: How to get Day of Week as String?

Post by Saman » Mon Mar 05, 2012 9:41 pm

It is correct. But it will only show the short form of day such as Sat for Saturday, Mon for Monday. If you want the full name, use without 2nd parameter.
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: How to get Day of Week as String?

Post by Nandika » Tue Mar 06, 2012 2:40 pm

Thank you Saman,
I cant test my code.because,i haven't VB6.

Thanx lotb Sman..... :clap:
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: How to get Day of Week as String?

Post by Nandika » Tue Mar 06, 2012 10:49 pm

Hi Chamith8, :biggrin:

I asked your problem from EC,inserted of you.Now you can ask question directly.

Ok

you must say thanks to Saman. :)
Post Reply

Return to “Visual Basic Programming”