Page 1 of 1

How to get Day of Week as String?

Posted: Sun Mar 04, 2012 11:57 pm
by Nandika
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

Re: How to get Day of Week as String?

Posted: Mon Mar 05, 2012 10:13 am
by Saman
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 ;)

Re: How to get Day of Week as String?

Posted: Mon Mar 05, 2012 8:26 pm
by Nandika
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...

Re: How to get Day of Week as String?

Posted: Mon Mar 05, 2012 8:45 pm
by Nandika
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

Re: How to get Day of Week as String?

Posted: Mon Mar 05, 2012 9:41 pm
by Saman
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.

Re: How to get Day of Week as String?

Posted: Tue Mar 06, 2012 2:40 pm
by Nandika
Thank you Saman,
I cant test my code.because,i haven't VB6.

Thanx lotb Sman..... :clap:

Re: How to get Day of Week as String?

Posted: Tue Mar 06, 2012 10:49 pm
by Nandika
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. :)