PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: Has anybody any examples on datetime conversions and functions
Date: Mar 5 1998 8:59PM

Steve Allen wrote:
> 
> Folks,
> looking for examples and advise on datetime features to change spl to
> sybperl.
> 

Well the datepart() dont' exist as such, but you could do something
like (assuming that $startdate is a Sybase::DBlib::DateTime
object and $dbh is a DBlib handle):

($year, $mon, $mon_day, $year_day, $week_day, $hour,
 $min, $sec, $msec, $zone) = $startdate->crack;
if($week_day >= 2) {
	$startdate = $startdate->calc(-($week_day-2), 0);
} else {
	$startdate = $startdate->calc(1, 0);
}
($year, $mon, $mon_day, $year_day, $week_day, $hour,
 $min, $sec, $msec, $zone) = $startdate->crack;
$startdate = $dbh->newdate("$year$mon$mon_day");
$finishdate = $startdate->calc(7, 0);

This off the top of my head - so there may be problems with this...

Michael

> eg.
> if(select datepart(weekday,@startdate))>=2
>         begin /* find date of monday for this week */
>                 select @startdate =
> dateadd(day,-(datepart(weekday,@startdate) - 2),@startdate)
>         end
> else
>         begin /* sunday (day 1) should show week starting from following
> day */
>                 select @startdate = dateadd(day,+1,@startdate)
>         end
> 
> /* force time part of date to be 12:00AM */
> select @chardate = convert(char(8),@startdate,1)
> select @startdate = convert(datetime,@chardate)
> 
> /* set finishdate at 12:00 AM in 7 days */
> select @finishdate = dateadd(day,+6,@startdate)
> 
> any help would be appreciated.

-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@datamig.com    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com